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:asotolo...@uci.cu] Enviado el: jueves, 24 de mayo de 2012 13:08 Para: Conrado Blasetti CC: pgsql-es-ayuda@postgresql.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 [http://universidad.uci.cu/email.gif]<http://www.uci.cu/>