complex column definition in query

From: Seb <spluque(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: complex column definition in query
Date: 2009-06-02 22:16:09
Message-ID: 87iqjep9hy.fsf@patagonia.sebmags.homelinux.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

Say we have a table:

SELECT * FROM weather;
city | temp_lo | temp_hi | prcp
---------------+---------+---------+-------
San Francisco | 46 | 50 | 0.25
San Francisco | 43 | 57 | 0
Hayward | 37 | 54 |
Hayward | 30 | 58 |
Somewhere | 25 | 60 |
Somewhere | 28 | 50 |
(6 rows)

I'm struggling to build a query with a column temp, where the first row
is the lowest temp_lo followed by all the temp_hi for each city. So
this would be the output:

city | temp
---------------+------
San Francisco | 43
San Francisco | 50
San Francisco | 57
Hayward | 30
Hayward | 54
Hayward | 58
Somewhere | 25
Somewhere | 60
Somewhere | 50
(6 rows)

Any ideas appreciated! Thanks.

Cheers,

--
Seb

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2009-06-03 00:56:12 Re: [SQL] proposal for a CookBook in postgresql.org
Previous Message Alvaro Herrera 2009-06-02 21:10:57 Re: [SQL] proposal for a CookBook in postgresql.org