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:asotolo...@uci.cu]
Enviado el: jueves, 24 de mayo de 2012 12:33
Para: Conrado Blasetti
CC: pgsql-es-ayuda@postgresql.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/>

Reply via email to