From: Frank Bax <fbax@sympatico.ca>
To: javier garcia <andresjavier.garcia@wanadoo.es>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: union query doubt:
Date: Wed, 11 Dec 2002 11:39:14 -0500
Message-ID: <5.1.1.6.0.20021211113406.00a08510@pop6.sympatico.ca> (raw)
In-Reply-To: <200212111616.gBBGG3Q29502@natura.cebas.csic.es>
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
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: fbax@sympatico.ca, andresjavier.garcia@wanadoo.es
Subject: Re: union query doubt:
In-Reply-To: <5.1.1.6.0.20021211113406.00a08510@pop6.sympatico.ca>
* 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