From: | angel Nuñez Conde <afiladostoledo(at)gmail(dot)com> |
---|---|
To: | pgsql-es-ayuda(at)postgresql(dot)org |
Subject: | agrupar totales por años y por meses en una misma consulta |
Date: | 2009-09-01 17:49:55 |
Message-ID: | 1251827395.8003.4.camel@pc-taller |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Diego Ayala | 2009-09-01 18:18:37 | ayuda para implementar replicacion |
Previous Message | Jared Lopez | 2009-09-01 13:35:48 | Re: Sobre logo y plegables |