Re: matrix query? - Mailing list pgsql-general

From pgsql@ajornet.com
Subject Re: matrix query?
Date
Msg-id 12132139584.20020801214115@ajornet.com
Whole thread Raw
In response to matrix query?  (Jim Mercer <jim@reptiles.org>)
List 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@ajornet.com



pgsql-general by date:

Previous
From:
Date:
Subject: Re: MySQL or Postgres ?
Next
From: Andrew Sullivan
Date:
Subject: Re: Schedule Jobs from within Postgresql db