Re: [SQL] Calculate the ratio

2011-08-15 Thread Andreas Forø Tollefsen
Great. This works like I wanted. Thanks!

Re: [SQL] Calculate the ratio

2011-08-15 Thread David Johnston
efsen Sent: Monday, August 15, 2011 8:22 AM To: pgsql-sql@postgresql.org Subject: [SQL] Calculate the ratio Hi all, This is probably quite simple. I want to calculate the ratio of each country (gwcode) which experiences a 1 in one column (cf). Structure: gid; gridyear; gwcode; area

Re: [SQL] Calculate the ratio

2011-08-15 Thread David Johnston
, August 15, 2011 8:22 AM To: pgsql-sql@postgresql.org Subject: [SQL] Calculate the ratio Hi all, This is probably quite simple. I want to calculate the ratio of each country (gwcode) which experiences a 1 in one column (cf). Structure: gid; gridyear; gwcode; area; cf I want to

Re: [SQL] Calculate the ratio

2011-08-15 Thread msi77
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

[SQL] Calculate the ratio

2011-08-15 Thread Andreas Forø Tollefsen
Hi all, This is probably quite simple. I want to calculate the ratio of each country (gwcode) which experiences a 1 in one column (cf). Structure: gid; gridyear; gwcode; area; cf I want to select the SUM(area) WHERE cf = 1 into one column, and SUM(area) WHERE cf = 0 into another column and grou