Search Postgresql Archives

Re: Find min year and min value

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

 



Alternately, you could have a gdp table and a fish_catch table which
would be easily joined to give the same result.

Expanding on this:

create table fish_catches (country text not null,
                           data_year date not null,
                           primary key (country, data_year),
                           fish_catch numeric not null);

create table gdp (country text not null reference countries
                  data_year date not null,
                  primary key (country, data_year),
                  gdp numeric not null);

This makes your queries quite simple:

select country, data_year, fish_catch, gdp
from fish_catches
natural join gdp
where country = :country
order by data_year
limit 1;

Hmmm..... Don't really get that query working. My SQL looks like this now:

SELECT
   id_country,
   year,
   value
FROM
  internet_users
NATURAL JOIN
  gdp
WHERE
   id_country = 8
ORDER BY
   year
LIMIT
   1

But there is no result.

My table looks like this (for each variable one table):

id_country            year                value
4                           1980               6.6
4                           1981               7.0
...
6                           1980               5.1


Thanks for any advice!

Stef


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not
      match

[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