Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/06/2009, 13:25
zerts
 
Fecha de Ingreso: junio-2009
Ubicación: Bogota
Mensajes: 16
Antigüedad: 14 años, 10 meses
Puntos: 0
Pregunta Sumar Columna tipo TIME

hola a todos
Al sumar datos tipo TIME encontré un problema cuando supera a 838:59:59, ya que tiene un rango va de -838:59:59 a 838:59:59, Cuando es inferior es fácil
Código sql:
Ver original
  1. SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(tothra)))AS 'HORAS_TOTALES'
  2. FROM hratra
para solucionarlo hice esto, pero la verdad no me convence
Código sql:
Ver original
  1. SELECT CONCAT( (
  2.  
  3. SELECT IF( (
  4. SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) ) ) > '59',
  5. SUBSTRING( (SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) ) /60 ) , 1, INSTR( (SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) ) /60 ) , '.' ) -1) + ( SUM( SUBSTRING( tothra, 1, INSTR( tothra, ':' ) -1 ) ) ) ,
  6. SUM( SUBSTRING( tothra, 1, INSTR( tothra, ':' ) -1 ) )
  7. )
  8. ), ':', (
  9.  
  10. SELECT IF( (
  11. SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) ) ) > '59', MOD( SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) ) , 60 ) , SUM( SUBSTR( tothra, INSTR( tothra, ':' ) +1 ) )
  12. )
  13. )
  14. ) AS 'HORAS_TOTALES'
  15. FROM hratra
Si alguien tiene una mejor forma o pude mejorar la que ya tengo seria estupendo.

Les agradezco mucho si me pueden colaborar, muchas gracias de antemano