Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 0EA5F635080 for ; Tue, 2 Jun 2009 19:15:12 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 98736-04-2 for ; Tue, 2 Jun 2009 19:15:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mail.postgresql.org (Postfix) with ESMTP id 655AF634E1F for ; Tue, 2 Jun 2009 19:15:09 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MBcGC-0002BV-GX for pgsql-sql@postgresql.org; Tue, 02 Jun 2009 22:15:08 +0000 Received: from s01060015e975d7fb.wp.shawcable.net ([24.77.73.195]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jun 2009 22:15:08 +0000 Received: from spluque by s01060015e975d7fb.wp.shawcable.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 02 Jun 2009 22:15:08 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Seb Subject: complex column definition in query Date: Tue, 02 Jun 2009 17:16:09 -0500 Organization: Church of Emacs Lines: 39 Message-ID: <87iqjep9hy.fsf@patagonia.sebmags.homelinux.org> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: s01060015e975d7fb.wp.shawcable.net User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.94 (gnu/linux) Cancel-Lock: sha1:UafHYhHGsX/Y+QaqHE95FnAO2+0= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200906/12 X-Sequence-Number: 32617 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