Ver Mensaje Individual
  #12 (permalink)  
Antiguo 07/04/2008, 17:02
Avatar de [NiRVaNa]
[NiRVaNa]
 
Fecha de Ingreso: abril-2004
Ubicación: Someplace In The Middle Of Nowhere!
Mensajes: 325
Antigüedad: 20 años, 1 mes
Puntos: 6
Exclamación Re: Consulta de comparacion en 3 años

Actualmente mi consulta quedo asi:

Código:
select codsede, DATE(fec) as fecha, anho, count(cant1) as cant1, count(cant2) as cant2, count(cant3) as cant3
from 
(
select  cs.codsede, cs.anho, si.fecins as fec, cs.semestre,
case when date_part('year', si.fecins) = 2006 then 1 else null end as cant1,
case when date_part('year', si.fecins) = 2007 then 1 else null end as cant2,
case when date_part('year', si.fecins) = 2008 then 1 else null end as cant3

from inscasig i

/*
Multiples joins
*/

where cs.codsede = 'SE'
and   cs.semestre = 1
and   si.aprobado = 'S'
and   si.codtipoinsc != 'REC'
and date(si.fecins) >= '01/01/2006' and date(si.fecins) <= '01/01/2008'

group by cs.codsede, fec, cs.anho, cs.semestre
order by fec
) as lista

group by codsede, fecha, anho
order by fecha
Ahora bien, tengo una pregunta tonta, como hago para hacer el select de la fecha sin el año? porque no se como hacerlo, y asi como esta, no hace lo que necesito todavia...

Devuelve este tipo de resultados

Fecha | cant1(año1) | cant2(año2)
01/01/2007 | 25 | 0
01/02/2007 | 10 | 0
01/02/2008 | 0 | 20

y en teoria los ultimos 2 resultados tendrian que estar en una misma fila...