Re: group by and one column per month?

From: Torbj=?ISO-8859-1?B?9g==?=rn Andersson <tobbe(at)embryo(dot)se>
To: Harald Lux <info(at)lux(dot)de>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: group by and one column per month?
Date: 2002-01-30 21:37:24
Message-ID: B87E2624.14B2%tobbe@embryo.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

02-01-30 22.10 Harald Lux info(at)lux(dot)de

> But instead of one column with the whole revenue (first example) or the
> renvenue of one month
> (second example) I would like to have a column for each month. is this
> possible within one select
> statement?

It is possible if you create virtual tables for each month. Somthing like
the following should work:

SELECT t.dealer, sum(jan.revenue) AS jan, ......, sum(dec.revenue) AS dec
FROM table t
INNER JOIN (SELECT dealer, revenue, from table where date_part('month',
vdate) = 1) AS jan USING(dealer)
.....
INNER JOIN (SELECT dealer, revenue, from table where date_part('month',
vdate) = 12) AS dec USING(dealer)
GROUP BY dealer;

Regards,

Torbjörn Andersson
---------------------------------------------------
Embryo Communication phone: +46 (0) 31-774 39 11(00)
Kungsgatan 7a fax: +46 (0)31 774 07 80
S-411 19 Göteborg mobile: 0708-30 70 04
Sweden home: http://www.embryo.se/
mail: torbjorn(dot)andersson(at)embryo(dot)se
---------------------------------------------------
"Att idag tänka annorlunda än igår skiljer den vise från den envise." — John
Steinbeck

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Steve Boyle (Roselink) 2002-01-30 22:37:42 Re: Function Problem
Previous Message Harald Lux 2002-01-30 21:10:47 group by and one column per month?