Re: [GENERAL] Find min year and min value

2007-10-05 Thread Michael Glaesemann
On Oct 5, 2007, at 4:11 , Stefan Schwarzer wrote: 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,

Re: [GENERAL] Find min year and min value

2007-10-05 Thread Stefan Schwarzer
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 Ok, got it working with another proposed SQL SELECT. This is a solution (comes out

Re: [GENERAL] Find min year and min value

2007-10-05 Thread Stefan Schwarzer
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_yea

Re: [GENERAL] Find min year and min value

2007-10-04 Thread Michael Glaesemann
On Oct 4, 2007, at 6:41 , Stefan Schwarzer wrote: So, "value" is something general - it can be (measured in) (thousand) Dollars, (Million) People, (Hundred) Hectares etc... Then I would make a separate table for each variable (as I described above). For one thing, you're going to have keep

Re: [GENERAL] Find min year and min value

2007-10-04 Thread Stefan Schwarzer
Having 500 statistical global national variables for about 240 countries/territories. Need to do regional aggregations, per Capita calculations and some completeness computations on-the-fly. id_variable |year|value |id_country Both Steve and I have given you alternat

Re: [GENERAL] Find min year and min value

2007-10-03 Thread Michael Glaesemann
On Oct 3, 2007, at 1:29 , Stefan Schwarzer wrote: As others have noted, the query *can* be written. But it appears to me that you are struggling against your table layout. The current schema he has is commonly called EAV (entity-attribute- value) and is generally frowned upon. Now, in his

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Stefan Schwarzer
As others have noted, the query *can* be written. But it appears to me that you are struggling against your table layout. The current schema he has is commonly called EAV (entity-attribute- value) and is generally frowned upon. Now, in his particular case it may be justified if the "value"

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Michael Glaesemann
On Oct 2, 2007, at 11:10 , Steve Crawford wrote: As others have noted, the query *can* be written. But it appears to me that you are struggling against your table layout. The current schema he has is commonly called EAV (entity-attribute- value) and is generally frowned upon. Now, in his par

Re: [GENERAL] Find min year and min value

2007-10-02 Thread hubert depesz lubaczewski
On Tue, Oct 02, 2007 at 04:29:02PM +0200, Stefan Schwarzer wrote: > If I want to find the "common smallest year" for two given variables > (say, I have years 1970, 1971, 2005 for variable 1 (GDP) and > 1980, 1981,... 2003) for variable 2 (Fish Catch) ). It should come up > with 1980 for a

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Steve Crawford
Stefan Schwarzer wrote: >> SELECT year, value FROM ... > > I feel ashamed such a simple solution... gush Thanks for that! > > Unfortunately it doesn't stop there... > > If I want to find the "common smallest year" for two given variables > (say, I have years 1970, 1971, 2005 for vari

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Michael Glaesemann
On Oct 2, 2007, at 9:29 , Stefan Schwarzer wrote: How would I do that? I really have no clue... The key is to build it up in steps. select id_country, year, var_1, val_1, var_2, val_2 -- Second step: -- value for year for each country of var_1 from (select id_country, year, id_variable as va

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Richard Huxton
Stefan Schwarzer wrote: SELECT year, value FROM ... I feel ashamed such a simple solution... gush Thanks for that! Can be easy to over-complicate things when you've been thinking about them too long. Unfortunately it doesn't stop there... If I want to find the "common smallest ye

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Stefan Schwarzer
SELECT year, value FROM ... I feel ashamed such a simple solution... gush Thanks for that! Unfortunately it doesn't stop there... If I want to find the "common smallest year" for two given variables (say, I have years 1970, 1971, 2005 for variable 1 (GDP) and 1980, 1981,... 200

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Richard Huxton
Stefan Schwarzer wrote: Hi there, I am trying to find in a table with different variables, countries and years the lowest year and within that year the lowest value The following SELECT works, but I wonder if it is "elegant". Can you recommend any other solution? SELECT value AS minv

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Stefan Schwarzer
Hi there, I am trying to find in a table with different variables, countries and years the lowest year and within that year the lowest value The following SELECT works, but I wonder if it is "elegant". Can you recommend any other solution? SELECT value AS minv FROM public_on_table.d

Re: [GENERAL] Find min year and min value

2007-10-02 Thread Richard Huxton
Stefan Schwarzer wrote: Hi there, I am trying to find in a table with different variables, countries and years the lowest year and within that year the lowest value The following SELECT works, but I wonder if it is "elegant". Can you recommend any other solution? SELECT value A

[GENERAL] Find min year and min value

2007-10-02 Thread Stefan Schwarzer
Hi there, I am trying to find in a table with different variables, countries and years the lowest year and within that year the lowest value The following SELECT works, but I wonder if it is "elegant". Can you recommend any other solution? SELECT