Ver Mensaje Individual
  #3 (permalink)  
Antiguo 17/01/2012, 06:18
Avatar de repara2
repara2
 
Fecha de Ingreso: septiembre-2010
Ubicación: München
Mensajes: 2.445
Antigüedad: 13 años, 7 meses
Puntos: 331
Respuesta: no se estructurar una consulta mysql

Te paso un ejemplo.
Si guardas las fechas como timestamp() (entero de 10 posciones), la tabla te puede quedar así:

Código MySQL:
Ver original
  1. /*Table structure for table `apuntes` */
  2.  
  3.  
  4.  
  5. DROP TABLE IF EXISTS `apuntes`;
  6.  
  7.  
  8.  
  9. CREATE TABLE `apuntes` (
  10.  
  11.   `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Id unico',
  12.  
  13.   `fecha` int(10) DEFAULT NULL COMMENT 'Timestamp',
  14.  
  15.   `importe` double(6,2) DEFAULT NULL COMMENT 'Importe en moneda',
  16.  
  17.   `observaciones` varchar(256) DEFAULT NULL COMMENT 'Informativo',
  18.  
  19.   PRIMARY KEY (`id`)
  20.  
  21. ) ENGINE=MyISAM AUTO_INCREMENT=18 DEFAULT CHARSET=latin1;
  22.  
  23.  
  24.  
  25. /*Data for the table `apuntes` */
  26.  
  27.  
  28.  
  29. insert  into `apuntes`(`id`,`fecha`,`importe`,`observaciones`) values (1,1326902349,100.00,'Ventas de hoy aprox.: 100.00'),(2,1327002349,123.00,'Ventas de hoy aprox.: 123.00'),(3,1327102349,123.00,'Ventas de hoy aprox.: 123.00'),(4,1327202349,12.00,'Ventas de hoy aprox.: 12.00'),(5,1327302349,4545.00,'Ventas de hoy aprox.: 4545.00'),(6,1327402349,6565.00,'Ventas de hoy aprox.: 6565.00'),(7,1327502349,767.00,'Ventas de hoy aprox.: 767.00'),(8,1327602349,67.00,'Ventas de hoy aprox.: 67.00'),(9,1327702349,67.00,'Ventas de hoy aprox.: 67.00'),(10,1327802349,9999.99,'Ventas de hoy aprox.: 9999.99'),(11,1327902349,678.00,'Ventas de hoy aprox.: 678.00'),(12,1328002349,6546.00,'Ventas de hoy aprox.: 6546.00'),(13,1328102349,9999.99,'Ventas de hoy aprox.: 9999.99'),(14,1328202349,6654.00,'Ventas de hoy aprox.: 6654.00'),(15,1328302349,775.00,'Ventas de hoy aprox.: 775.00'),(16,1328402349,678.00,'Ventas de hoy aprox.: 678.00'),(17,1328502349,867.00,'Ventas de hoy aprox.: 867.00');

Ejecuta esa select y prueba estas consultas:

Código MySQL:
Ver original
  1. #Semana actual
  2. #Apuntes de la semana actual
  3. SELECT * FROM apuntes WHERE WEEK(FROM_UNIXTIME(fecha, "%Y-%m-%d")) = WEEK(NOW());
  4. #Fechas y semanas
  5. SELECT WEEK(FROM_UNIXTIME(fecha, "%Y-%m-%d")) AS semana, FROM_UNIXTIME(fecha, "%Y-%m-%d") AS fecha FROM apuntes;
  6. #Ventas por semana
  7. SELECT WEEK(FROM_UNIXTIME(fecha, "%Y-%m-%d")) AS semana, SUM(importe) AS ventas FROM apuntes GROUP BY WEEK(FROM_UNIXTIME(fecha, "%Y-%m-%d"));

Saluditos
__________________
Fere libenter homines, id quod volunt, credunt.