From: msi77 <msi77@yandex.ru>
To: pgsql-sql@postgresql.org
Subject: Re: Calculate the ratio
Date: Mon, 15 Aug 2011 17:00:37 +0400
Message-ID: <765121313413237@web108.yandex.ru> (raw)
In-Reply-To: <CAGMz7DnkL2=VxpYqEsqTnMS=MTyDywgu_Z+b79X9ugqn5BgHpg@mail.gmail.com>
References: <CAGMz7DnkL2=VxpYqEsqTnMS=MTyDywgu_Z+b79X9ugqn5BgHpg@mail.gmail.com>
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" <andreasft@gmail.com>:
> 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 group by gridyear and gwcode.
> Then i can see the ratio of the area of each country affected by cf.
>
> Any suggestions?
>
> Thanks.
>
> A.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: msi77@yandex.ru
Subject: Re: Calculate the ratio
In-Reply-To: <765121313413237@web108.yandex.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox