RE: Funcion ventana nueva consulta

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 15:38:03
Message-ID: 73A3A527647BB24F9587AA69EC1A4E16113A1962@sar001241.Mapfre.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-es-ayuda

Anthony, nuevamente gracias.
Bien, algo asi intenté pero, teniendo los tres ciclos (los unión), veo que el primero estaría ok (salvo que el limit me toma el primero en vez de sumar todos los acululados, veria de modificarlo).
Pero lo mas importante, es que, cuando se ejecuta el segundo select del unión, la agrupación se está haciendo sin tener en cuentra el acumulado del resumen anterior, y es justamente lo que necesitaría

No se si puedo expresar bien lo que necesito...

De: Anthony [mailto:asotolongo(at)uci(dot)cu]
Enviado el: jueves, 24 de mayo de 2012 12:33
Para: Conrado Blasetti
CC: pgsql-es-ayuda(at)postgresql(dot)org
Asunto: Re: [pgsql-es-ayuda] Funcion ventana nueva consulta

bueno tendras que hacer algo asi como:
(select null::date as fecha,tipo1, tipo2, sum(imp) over (order by id), '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' order by fecha desc limit 1)
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,tipo1, tipo2, sum(imp) over (order by id), '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)

-- order by fecha desc

[http://universidad.uci.cu/email.gif]<http://www.uci.cu/>

In response to

Responses

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Anthony 2012-05-24 16:07:43 Re: Funcion ventana nueva consulta
Previous Message Anthony 2012-05-24 15:33:00 Re: Funcion ventana nueva consulta