From: | Stefan Schwarzer <stefan(dot)schwarzer(at)grid(dot)unep(dot)ch> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Find min year and min value |
Date: | 2007-10-05 12:14:11 |
Message-ID: | CE8F0CD7-611C-43D4-90D0-BA2D68EF4C5B@grid.unep.ch |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
> 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 of an PHP loop, so one could easily have more
than 2 subselects). Thanks for the help to everyone!!
SELECT
year0 AS common_year,
v0.val0 AS v0_value,
v1.val1 AS v1_value
FROM
(
SELECT
year AS year0,
value AS val0
FROM
gdp_capita
WHERE
id_country = 672 AND
value IS NOT NULL
) AS v0,
(
SELECT
year AS year1,
value AS val1
FROM
agri_add_gdp
WHERE
id_country = 672 AND
value IS NOT NULL
) AS v1
WHERE
v1.year1 = v0.year0 AND
v1.year1 = v1.year1
ORDER BY
v0.year0
LIMIT
1
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Glaesemann | 2007-10-05 12:27:43 | Re: How to convert rows into HTML columns? |
Previous Message | Alban Hertroys | 2007-10-05 12:00:59 | Re: Slow TSearch2 performance for table with 1 million documents. |