From: | Conrado Blasetti <conrado(at)mapfre(dot)com(dot)ar> |
---|---|
To: | Anthony <asotolongo(at)uci(dot)cu> |
Cc: | "pgsql-es-ayuda(at)postgresql(dot)org" <pgsql-es-ayuda(at)postgresql(dot)org> |
Subject: | RE: Funcion ventana nueva consulta |
Date: | 2012-05-24 16:08:59 |
Message-ID: | 73A3A527647BB24F9587AA69EC1A4E16113A199A@sar001241.Mapfre.ar |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
Exacto, solo que el acumulado del primer detalle tendría que comenzar con el acumulado del resumen anterior.
Pero si, creo que debería hacerlo directamente desde una función y tirar los datos de a uno.
Muchas gracias!
De: Anthony [mailto:asotolongo(at)uci(dot)cu]
Enviado el: jueves, 24 de mayo de 2012 13:08
Para: Conrado Blasetti
CC: pgsql-es-ayuda(at)postgresql(dot)org
Asunto: Re: [pgsql-es-ayuda] Funcion ventana nueva consulta
buneo lo mejor que puedo hacer con solo SQL es esto:
(select null::date as fecha,sum(tipo1), sum(tipo2), sum(tipo1+(tipo2*-1)), 'Resumen'::text
from (select id, fecha, imp as tipo1, 0 as tipo2, imp
from foo
where tipo= 1
union
select id, fecha, 0 as tipo1, imp as tipo2, imp*-1
from foo
where tipo= 2) as Aux
where fecha <= '2012-04-01' )
union all
(select fecha,tipo1, tipo2, sum(imp) over (order by id), 'Detalle'::text
from (select id, fecha, imp as tipo1, 0 as tipo2, imp
from foo
where tipo= 1
union
select id, fecha, 0 as tipo1, imp as tipo2, imp*-1
from foo
where tipo= 2) Aux
where fecha between '2012-04-01' and '2012-04-30')
union all
(select null::date as fecha,sum(tipo1), sum(tipo2), sum(tipo1+(tipo2*-1)), 'Resumen'::text
from (select id, fecha, imp as tipo1, 0 as tipo2, imp
from foo
where tipo= 1
union
select id, fecha, 0 as tipo1, imp as tipo2, imp*-1
from foo
where tipo= 2) as Aux
where fecha >= '2012-04-30' order by fecha desc limit 1)
si entiendo bien lo que me pides tendrás que hacerlo con una función en plpgsql usando cursores.
saludos
From | Date | Subject | |
---|---|---|---|
Next Message | listaconsulta | 2012-05-24 16:10:46 | Insert automáticos en tablas (Ejecución programada mensual) |
Previous Message | Anthony | 2012-05-24 16:07:43 | Re: Funcion ventana nueva consulta |