agrupar totales por años y por meses en una misma consulta

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 11:42:56
Message-ID: 1251805376.8338.40.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.

un saludo Angel

Browse pgsql-es-ayuda by date

  From Date Subject
Next Message Gilberto Castillo Martínez 2009-09-01 12:23:56 Sobre logo y plegables
Previous Message Edwin Quijada 2009-08-31 23:12:05 Re: [pgsql-es-fomento] [pgsql-es-ayuda] Propuesta de logo para PgDayLatiniamerica.