Search Postgresql Archives

Re: Database/Table Design for Global Country Statistics

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux