Ver Mensaje Individual
  #5  
Antiguo 18-12-2010
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.410
Reputación: 22
fjcg02 Va camino a la fama
Aunque ya te han contestado ( y muy bien por cierto), yo suelo utilizar consultas de este tipo, que me han proporcionado muchas satisfacciones ante mis clientes.
Tienes meses, trimestres o lo que quieras.
Lógicamente, hay que preparar las agrupaciones, filtrar por fechas, ... pero el esqueleto es más que aprovechable. Y dándole una vuelta, se pueden conseguir resultados muy chulos.

Código SQL [-]
select
SUM(case when extract(month from loga) = 1 then PRIMARECIBO else 0 end) AS ENERO,
SUM(case when extract(month from loga) = 2 then PRIMARECIBO else 0 end) AS FEBRERO,
SUM(case when extract(month from loga) = 3 then PRIMARECIBO else 0 end) AS MARZO,
SUM(case when extract(month from loga) = 4 then PRIMARECIBO else 0 end) AS ABRIL,
SUM(case when extract(month from loga) = 5 then PRIMARECIBO else 0 end) AS MAYO,
SUM(case when extract(month from loga) = 6 then PRIMARECIBO else 0 end) AS JUNIO,
SUM(case when extract(month from loga) = 7 then PRIMARECIBO else 0 end) AS JULIO,
SUM(case when extract(month from loga) = 8 then PRIMARECIBO else 0 end) AS AGOSTO,
SUM(case when extract(month from loga) = 9 then PRIMARECIBO else 0 end) AS SEPTIEMBRE,
SUM(case when extract(month from loga) = 10 then PRIMARECIBO else 0 end) AS OCTUBRE,
SUM(case when extract(month from loga) = 11 then PRIMARECIBO else 0 end) AS NOVIEMBRE,
SUM(case when extract(month from loga) = 12 then PRIMARECIBO else 0 end) AS DICIEMBRE,
SUM(case when
          (extract(month from loga) >= 1 AND extract(month from loga) <= 3)
          then PRIMARECIBO else 0 end) AS TRIMESTRE1,
SUM(case when
          (extract(month from loga) >= 4 AND extract(month from loga) <= 6)
          then PRIMARECIBO else 0 end) AS TRIMESTRE2,
SUM(case when
          (extract(month from loga) >= 7 AND extract(month from loga) <= 9)
          then PRIMARECIBO else 0 end) AS TRIMESTRE3,
SUM(case when
          (extract(month from loga) >= 10 AND extract(month from loga) <= 12)
          then PRIMARECIBO else 0 end) AS TRIMESTRE4

from  RECIBO

Un saludo
__________________
Cuando los grillos cantan, es que es de noche - viejo proverbio chino -
Responder Con Cita