Great. This works like I wanted.
Thanks!
Replace the 1 in the case with area
like the msi77 said
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org]
On Behalf Of David Johnston
Sent: Monday, August 15, 2011 9:08 AM
To: 'Andreas Forø Tollefsen'; pgsql-sql@postgresql.org
Subject: Re: [SQL] Cal
SELECT cols,
SUM( CASE WHEN cf = 1 THEN 1 ELSE 0 END ) AS sum_1,
SUM ( CASE WHEN cf = 0 THEN 1 ELSE 0 END ) AS sum_0
FROM table
WHERE cf IN (0, 1)
GROUP BY cols
From: pgsql-sql-ow...@postgresql.org [mailto:pgsql-sql-ow...@postgresql.org]
On Behalf Of Andreas Forø Tollefsen
Sent: Monday,
Hi,
Try this
select gridyear, gwcode, sum(case when cf=1 then area else o end) as cf1,
sum(case when cf=0 then area else 0 end) as cf0
from table
group by gridyear, gwcode
http://sql-ex.ru/help/select8.php#case
15.08.2011, 16:21, "Andreas Forø Tollefsen" :
> Hi all,
>
> This is probably quite