Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 43795476606 for ; Wed, 11 Dec 2002 11:39:56 -0500 (EST) Received: from tomts22-srv.bellnexxia.net (tomts22.bellnexxia.net [209.226.175.184]) by postgresql.org (Postfix) with ESMTP id 851964764AB for ; Wed, 11 Dec 2002 11:39:55 -0500 (EST) Received: from acer.sympatico.ca ([65.93.64.111]) by tomts22-srv.bellnexxia.net (InterMail vM.5.01.04.19 201-253-122-122-119-20020516) with ESMTP id <20021211163959.HTVB13093.tomts22-srv.bellnexxia.net@acer.sympatico.ca>; Wed, 11 Dec 2002 11:39:59 -0500 Message-Id: <5.1.1.6.0.20021211113406.00a08510@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.1.1 Date: Wed, 11 Dec 2002 11:39:14 -0500 To: javier garcia , "pgsql-sql@postgresql.org" From: Frank Bax Subject: Re: union query doubt: In-Reply-To: <200212111616.gBBGG3Q29502@natura.cebas.csic.es> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 Content-Transfer-Encoding: 8bit Content-Type: text/plain; x-avg-checked=avg-ok-5EF06A9A; charset=us-ascii; format=flowed X-Archive-Number: 200212/128 X-Sequence-Number: 10716 At 11:21 AM 12/11/02, javier garcia wrote: >I've got a table with three fields: DATE, POINT, FLOW. The POINT field can >have values among 1 and 6. So, for a same date I have six different points >with the correspondings flows. >I would like to make a query to obtain something like: >DATE POINT1 POINT2 POINT3 POINT4 POINT5 POINT6 > >where for a date I have the flows data of the different points. SELECT date, case when point = 1 then flow else 0 end as flow1, case when point = 2 then flow else 0 end as flow2, case when point = 3 then flow else 0 end as flow3, case when point = 4 then flow else 0 end as flow4, case when point = 5 then flow else 0 end as flow5, case when point = 6 then flow else 0 end as flow6 from samples There have been several messages recently about this - search on crosstab or pivot - a couple of other options were presented. Frank