pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Seb <spluque@gmail.com>
To: pgsql-sql@postgresql.org
Subject: complex column definition in query
Date: Tue, 02 Jun 2009 17:16:09 -0500
Message-ID: <87iqjep9hy.fsf@patagonia.sebmags.homelinux.org> (raw)

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




view thread (4+ messages)  latest in thread

Message-ID: <87iqjep9hy.fsf@patagonia.sebmags.homelinux.org>
Permalink:  ../87iqjep9hy.fsf@patagonia.sebmags.homelinux.org/
Also on:    postgresql.org/message-id/87iqjep9hy.fsf@patagonia.sebmags.homelinux.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: spluque@gmail.com
  Subject: Re: complex column definition in query
  In-Reply-To: <87iqjep9hy.fsf@patagonia.sebmags.homelinux.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox