Re: pivoting data? - Mailing list pgsql-general

From Joy Smith
Subject Re: pivoting data?
Date
Msg-id CAJqhhiP5ZXt-O+f07EGoMXbpU0qmmb+Ymq9eJuVrKVTVXYqfAg@mail.gmail.com
Whole thread Raw
In response to Re: pivoting data?  (Joy Smith <freestuffanddeals@gmail.com>)
List 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

pgsql-general by date:

Previous
From: Lincoln Yeoh
Date:
Subject: Re: conditional insert
Next
From: Andrew Sullivan
Date:
Subject: Re: conditional insert