Hola a todos. Soy novato en postgresql, tengo una vista con los campos id int fecha date total numeric
agrupo por meses mediante la consulta : select date_part('year',w.fecha) as año , date_part('month'::text, w.fecha)as mes, sum(w.total) as total_mes from w_totalalbaran w where w.fecha between '25-08-1998' and '31-12-1999' group by date_part('year',w.fecha), date_part('month'::text, w.fecha) order by 1,2 o por años: select date_part('year',w.fecha) as año , sum(w.total) as total_mes from w_totalalbaran w where w.fecha between '25-08-1998' and '31-12-1999' group by date_part('year',w.fecha)order by 1,2 quiero una consulta que me de totales de meses y años, no se como hacerlo. He intentado una subconsulta pero no funciona me da ERROR: una subconsulta utilizada como expresión retornó más de un registro le consulta es: select date_part('year',w.fecha) as año ,(select sum(total) as total_año from w_totalalbaran where w.fecha between '25-08-1998' and '31-12-1999' group by date_part('year',w.fecha)order by 1 ), date_part('month'::text, w.fecha)as mes, sum(w.total) as total_mes from w_totalalbaran w where w.fecha between '2-08-1998' and '31-12-2999' group by date_part('year',w.fecha), date_part('month'::text, w.fecha) order by 1,2 un saludo Angel -- TIP 4: No hagas 'kill -9' a postmaster