Ver Mensaje Individual
  #3 (permalink)  
Antiguo 26/05/2009, 19:56
chelodelsur
 
Fecha de Ingreso: abril-2008
Mensajes: 208
Antigüedad: 16 años, 1 mes
Puntos: 2
Respuesta: Agrupar datetime por medias horas?? se puede???

Esta consulta me trae la suma de contactos agrupados por:
Año, mes, día, fecha, hora.

Código mysql:
Ver original
  1. Year(fecha_date2) as `año`,    
  2. WHEN MONTH(fecha_date2) = 1 THEN "enero"  
  3. WHEN MONTH(fecha_date2) = 2 THEN "febrero"
  4. WHEN MONTH(fecha_date2) = 3 THEN "marzo"  
  5. WHEN MONTH(fecha_date2) = 4 THEN "abril"  
  6. WHEN MONTH(fecha_date2) = 5 THEN "mayo"  
  7. WHEN MONTH(fecha_date2) = 6 THEN "junio"  
  8. WHEN MONTH(fecha_date2) = 7 THEN "julio"  
  9. WHEN MONTH(fecha_date2) = 8 THEN "agosto"  
  10. WHEN MONTH(fecha_date2) = 9 THEN "septiembre"  
  11. WHEN MONTH(fecha_date2) = 10 THEN "octubre"  
  12. WHEN MONTH(fecha_date2) = 11 THEN "noviembre"  
  13. WHEN MONTH(fecha_date2) = 12 THEN "diciembre"  
  14. ELSE "NUUL_MES" END)  AS MES ,    
  15.  CASE
  16.    WHEN weekday(fecha_date2) = 0 THEN "Lunes"
  17.    WHEN weekday(fecha_date2) = 1 THEN "Martes"
  18.    WHEN weekday(fecha_date2) = 2 THEN "Miercoles"
  19.    WHEN weekday(fecha_date2) = 3 THEN "Jueves"
  20.    WHEN weekday(fecha_date2) = 4 THEN "Viernes"
  21.    WHEN weekday(fecha_date2) = 5 THEN "Sabado"
  22.    WHEN weekday(fecha_date2) = 6 THEN "Domingo"
  23.    ELSE "NUUL_DIA" END AS `DIA`,
  24. date_format(fecha_date2,'%Y-%m-%d') as fecha,
  25. hour(fecha_date2) as hora,
  26. sum(if(recibido= '',0,recibido)) as Recibido
  27. From Reg_15_minutos
  28. Where fecha_date between '2009-03-01 00:00:00' and '2009-05-30 23:59:00'
  29. group by year(fecha_date2), month(fecha_date2), dayofmonth(fecha_date2), hour(fecha_date2)
  30. order by year(fecha_date2) asc, month(fecha_date2) asc, weekday(fecha_date2)asc, dayofmonth(fecha_date2) asc,hour(fecha_date2) asc



Y me regresa la siguiente tabla.
+------+-------+---------+------------+------+----------+
| año | MES | DIA | fecha | hora | Recibido |
+------+-------+---------+------------+------+----------+
| 2009 | MARZO | Domingo | 2009-03-01 | 4 | 9 |
| 2009 | MARZO | Domingo | 2009-03-01 | 5 | 9 |
| 2009 | MARZO | Domingo | 2009-03-01 | 6 | 14 |
| 2009 | MARZO | Domingo | 2009-03-01 | 7 | 7 |
+------+-------+---------+------------+------+----------+

Pero lo que necesito ahora es que me de lo recibido agrupado por año, mes, dia, fecha y cada media hora, o sea para el ejemplo:

4:00
4:30
5:00
5:30 etc


espero se entienda

Y por supúesto gracias por la ayuda

Chelodelsur