Hola Aland, puedes utilizar:
sum(case when genero = 'X' then tucantidad end) as Masculino
por ejemplo puede ser
select year, month,
sum(case when genero = 'M' then cantidad end) as Masculino,
sum(case when genero = 'F' then cantidad end) as Femenino,
sum(cantidad)
from tu_consulta
group by 1,2
de aquí obtuve algo como
year, month,Masculino,Femenino, total
2013;1;145;55;200
2013;2;122;100;222
también puedes hacer los ajustes en tu_consulta y colocarle eso que te
pongo arriba con el sum (case when....)
saludos
El 2/5/2014 12:58 PM, Aland Laines escribió:
Hola, en realidad lo que deseo es distinto: si te das cuenta, en mi
consulta me devuelve:
Year Month Genero Cantidad
2013 1 M 145
2013 1 F 55
2013 2 M 122
2013 2 F 100
pero lo que necesito en realidad es
Year Month Masculino Femenino Total
2013 1 145 55 200
2013 2 122 100 222
Gracias de antemano por su ayuda,
*Aland Laines Calonge*
Twitter: @lainessolutions
Comunidad CakePHP en Español Google+
<https://plus.google.com/communities/106077549014949879129>
http://about.me/aland.laines
2014-02-05 Cesar Erices <caeri...@gmail.com <mailto:caeri...@gmail.com>>:
SELECT date_part('YEAR',"Postulante".
created) AS "Postulante__year",
date_part('MONTH',"Postulante".created) AS "Postulante__month",
"Persona".genero AS "Postulante__genero", count("Postulante".id)
AS "Postulante__cuenta"
FROM "produccion"."postulantes" AS "Postulante" LEFT JOIN
"produccion"."personas" AS "Persona" ON ("Postulante"."persona_id"
= "Persona"."id")
WHERE "Postulante"."estado" = 1 AND
date_part('YEAR',"Postulante".created) = '2013'
GROUP BY "Persona"."genero",
date_part('YEAR',"Postulante"."created"),
date_part('MONTH',"Postulante"."created")
ORDER BY date_part('YEAR',"Postulante".created) ASC,
date_part('MONTH',"Postulante".created) ASC
En la parte "Persona".genero AS "Postulante__genero" reelmplazar
por CASE "Persona".genero WHEN M THEN 'Masculino' ELSE 'Femenino'
END AS "Postulante__genero"
--
Sin más que decir se despide de Usted, muy atentamente
Cesar Erices Vergara
Ingeniero en Gestión Informática
Analista de Sistema
Especialista en ISO 27001 e ITIL
Cuenta Twitter: @caerices
Santiago - Chile
________________________________________________________________________________________________
III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del
2014. Ver www.uci.cu