Re: Database/Table Design for Global Country Statistics

From: Richard Huxton <dev(at)archonet(dot)com>
To: Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Database/Table Design for Global Country Statistics
Date: 2007-09-13 14:20:34
Message-ID: 46E94732.8040206@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stefan Schwarzer wrote:
> Just for the completeness, I attach the final working SQL query:
>
> SELECT
> f.year,
> f.id,
> c.name,
> (f.value / p.value) AS per_capita
> FROM
> fish_catch AS f
> JOIN
> pop_total AS p
> USING
> (year, id)
> INNER JOIN
> countries AS c ON f.id = c.id
> ORDER BY
> year

Make sure you fully specify the order:
ORDER BY year, f.id, c.name
It might work by chance a few times, but then return rows in an
unexpected order later.

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message wild_oscar 2007-09-13 14:37:03 GRANT on group does not give access to group members
Previous Message Stefan Schwarzer 2007-09-13 14:17:46 Re: Database/Table Design for Global Country Statistics