Ver Mensaje Individual
  #1  
Antiguo 01-05-2010
Avatar de Behemot
Behemot Behemot is offline
Miembro
 
Registrado: oct 2005
Posts: 15
Reputación: 0
Behemot Va por buen camino
Totales de sumatorias

Hola a todos, haber si me pueden ayudar con esto, el siguiente código funciona perfecto:

Código SQL [-]
SELECT di.cod_diag,  di.des_diag, sum(1) as cantidad,
SUM( Case pa.cod_sexo when 'F' then 1 else 0 end ) as SF,
SUM( Case pa.cod_sexo when 'M' then 1 else 0 end ) as SM,
SUM( Case when (hc.edad >=0 and hc.edad<=18 and pa.cod_sexo='F') then 1 else 0 end)  rangoF1,
SUM( Case when (hc.edad >18 and hc.edad<=35 and pa.cod_sexo='F') then 1 else 0 end)  rangoF2,
SUM( Case when (hc.edad >35 and hc.edad<=49 and pa.cod_sexo='F') then 1 else 0 end)  rangoF3,
SUM( Case when (hc.edad >=50 and hc.edad<=120 and pa.cod_sexo='F') then 1 else 0 end)  rangoF4,

SUM( Case when (hc.edad >=0 and hc.edad<=18 and pa.cod_sexo='M') then 1 else 0 end)  rangoM1,
SUM( Case when (hc.edad >18 and hc.edad<=35 and pa.cod_sexo='M') then 1 else 0 end)  rangoM2,
SUM( Case when (hc.edad >35 and hc.edad<=49 and pa.cod_sexo='M') then 1 else 0 end)  rangoM3,
SUM( Case when (hc.edad >=50 and hc.edad<=120 and pa.cod_sexo='M') then 1 else 0 end)  rangoM4



FROM TBL_HC_OFTALMOLOGIA_ hc

LEFT JOIN tbl_pacientes_ pa ON pa.clave = hc.clv_paciente
LEFT JOIN tbl_diagnosticos_ di ON di.cod_diag = hc.cod_diag1


WHERE 1=1 

AND (hc.estatus = 'A' )
AND (hc.cod_diag1>=:CodDiagIni) AND (hc.cod_diag1<=:CodDiagFin)
AND (pa.cod_entidad>=:CodEntidadIni) AND (pa.cod_entidad<=:CodEntidadFin)
AND  (hc.fecha >= :fechaini  AND hc.fecha <= :fechafin) 
AND  (hc.edad >= :EdadIni  AND hc.edad <= :EdadFin) 
AND  (hc.tipo_edad >= :TipoEdadIni  AND hc.tipo_edad <= :TipoEdadFin) 
AND  (pa.cod_sexo >= :GeneroIni  AND pa.cod_sexo <= :GeneroFin) 
AND  (hc.clv_usuario >= :ProfesionalIni  AND hc.clv_usuario <= :ProfesionalFin)

GROUP BY di.cod_diag,  di.des_diag
order by 3 desc

Lo que quiero ahora es saber el total del los rangos: rangoF1, rangoF2, ....
que debo hacer? no importa si es en otro SELECT diferente. Muchas Gracias.
Responder Con Cita