Re: matrix query?

From: pgsql(at)ajornet(dot)com
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: matrix query?
Date: 2002-08-01 19:41:15
Message-ID: 12132139584.20020801214115@ajornet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Bonjour Jim,

Le jeudi 1 août 2002 à 21:07:32, vous écriviez :

JM> what kind of select can i do to get:

JM> Day CustA CustB CustC
JM> 1 5 8 4
JM> 2 4 3 7
JM> 3 9 2 1

This one :
SELECT day,
SUM(CASE WHEN customer='CustA' THEN widgets ELSE 0 END) AS "CustA",
SUM(CASE WHEN customer='CustB' THEN widgets ELSE 0 END) AS "CustB",
SUM(CASE WHEN customer='CustC' THEN widgets ELSE 0 END) AS "CustC",
SUM(1) as Total
FROM DATA
GROUP BY day
See : http://php.weblogs.com/ADOdb_manual#pivot

--
Cordialement,
Daniel mailto:pgsql(at)ajornet(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2002-08-01 20:05:11 Re: getpid() function
Previous Message createtank 2002-08-01 19:20:14 Re: MySQL or Postgres ?