Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TocXc-0002OS-JH for pgsql-sql@arkaria.postgresql.org; Fri, 28 Dec 2012 16:12:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TocXc-0005ay-4F for pgsql-sql@arkaria.postgresql.org; Fri, 28 Dec 2012 16:12:12 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TocXb-0005at-Ds for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 16:12:11 +0000 Received: from einhorn.in-berlin.de ([192.109.42.8]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TocXa-0000kM-9m for pgsql-sql@postgresql.org; Fri, 28 Dec 2012 16:12:10 +0000 X-Envelope-From: ml@ft-c.de X-Envelope-To: Received: from [10.34.33.96] ([89.204.135.96]) (authenticated bits=0) by einhorn.in-berlin.de (8.13.6/8.13.6/Debian-1) with ESMTP id qBSGC6im026010 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 28 Dec 2012 17:12:09 +0100 Message-ID: <50DDC4D5.8010500@ft-c.de> Date: Fri, 28 Dec 2012 17:12:05 +0100 From: Franz Timmer Reply-To: ml@ft-c.de User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.10) Gecko/20121028 Icedove/10.0.10 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: Help with a select statement design References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang_at_IN-Berlin_e.V. on 192.109.42.8 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org hello, ( select 'A' as x, id, price from tab where id = 'value' union all select 'B' as x, id, ... union all select 'C' as x, id, ... union all select 'D' as x, id, price from tab where id = 'value' ) generate a list like X id price A 1 10 B 2 20 C 3 30 D 4 40 select max (case when X = 'A' then id end ) as id_a, max (case when X = 'A' then price end ) as price_a, max (case when X = 'B' then id end ) as id_b, max (case when X = 'B' then price end ) as price_b, max (case when X = 'C' then id end ) as id_c, max (case when X = 'C' then price end ) as price_c, max (case when X = 'D' then id end ) as id_d, max (case when X = 'D' then price end ) as price_d from ( table_or_select_from_above ) --- not testet On 24.12.2012 17:30, JORGE MALDONADO wrote: > I have a record with the following fields: > > id1, id2, id3, id4, price1, price2, price3, price4 > > I would like to write a SELECT statement in order to get 4 records: > > id, price (record that comes from id1 and price 1) > id, price (record that comes from id2 and price 2) > id, price (record that comes from id3 and price 3) > id, price (record that comes from id4 and price 4) > > I will very much appreciate any suggestion. > > Respectfully, > Jorge Maldonado -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql