Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > SQL
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

 
 
Herramientas Buscar en Tema Desplegado
  #5  
Antiguo 18-12-2010
Avatar de fjcg02
[fjcg02] fjcg02 is offline
Miembro Premium
 
Registrado: dic 2003
Ubicación: Zamudio
Posts: 1.418
Poder: 24
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
 


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
(SQL) Porqué usar parámetros en lugar de concatenar... Neftali [Germán.Estévez] La Taberna 3 27-01-2010 16:12:16
Como bloquear registros sin usar campos persistentes uper MS SQL Server 2 11-07-2007 18:10:06
usar variables de otras units anubis Varios 7 16-04-2007 09:24:04
DBGrid con campos variables mayte mtz SQL 9 15-11-2005 23:12:58
usar querys en lugar de tablas maruenda Varios 4 18-02-2004 23:03:13


La franja horaria es GMT +2. Ahora son las 01:23:10.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi