Find min year and min value

From: Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch>
To: pgsql-general(at)postgresql(dot)org
Subject: Find min year and min value
Date: 2007-10-02 13:26:17
Message-ID: F4D18345-B3E4-407C-983D-0DB79F981012@grid.unep.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
MIN(value) AS minv
FROM
public_one_table.data
WHERE
year =
(
SELECT
MIN(year) AS min_year
FROM
public_one_table.data
WHERE
id_variable = 1
) AND
id_variable = 1

Thanks for any help!

Stef

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Huxton 2007-10-02 13:40:11 Re: Find min year and min value
Previous Message Philippe Lang 2007-10-02 13:19:09 Execution plan caching