Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id DFA5B476344 for ; Wed, 11 Dec 2002 11:56:58 -0500 (EST) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id D8DDD476314 for ; Wed, 11 Dec 2002 11:56:57 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id LAA31985; Wed, 11 Dec 2002 11:56:59 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma031983; Wed, 11 Dec 02 11:56:56 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id LAA29749; Wed, 11 Dec 2002 11:55:27 -0500 Message-ID: <3DF76E6F.144FEA5A@nsd.ca> Date: Wed, 11 Dec 2002 11:57:19 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: Frank Bax Cc: javier garcia , "pgsql-sql@postgresql.org" Subject: Re: union query doubt: References: <5.1.1.6.0.20021211113406.00a08510@pop6.sympatico.ca> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/129 X-Sequence-Number: 10717 I think you meant: SELECT date, sum( case when point = 1 then flow else 0 end) as flow1, sum( case when point = 2 then flow else 0 end) as flow2, sum( case when point = 3 then flow else 0 end) as flow3, sum( case when point = 4 then flow else 0 end) as flow4, sum( case when point = 5 then flow else 0 end) as flow5, sum( case when point = 6 then flow else 0 end) as flow6 from samples group by date; Frank Bax wrote: > > 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 > > ---------------------------(end of broadcast)--------------------------- > TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org