Re: pivoting data?

From: Joy Smith <freestuffanddeals(at)gmail(dot)com>
To: Chris Travers <chris(dot)travers(at)gmail(dot)com>, sim(at)compulab(dot)co(dot)il
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: pivoting data?
Date: 2011-09-08 14:52:06
Message-ID: CAJqhhiP5ZXt-O+f07EGoMXbpU0qmmb+Ymq9eJuVrKVTVXYqfAg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

>You'll want to group by baloons,color and probably take a sum of each of
the case statements.

>Sim

yes, hard to believe I did not notice that. Thank you, the working query
is:

select baloons, color,
max(case when dayofpurchase = '2011-01-01' then amountpur ELSE NULL END) as
"first",
max(CASE when dayofpurchase = '2011-01-02' then amountpur ELSE NULL END) as
"second",
max(CASE when dayofpurchase = '2011-01-03' then amountpur ELSE NULL END) as
"third"
from modvalues
group by baloons, color

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2011-09-08 15:12:36 Re: conditional insert
Previous Message Lincoln Yeoh 2011-09-08 14:31:39 Re: conditional insert