X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 212D2D1B502 for ; Mon, 29 Sep 2003 19:50:42 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 57244-09 for ; Mon, 29 Sep 2003 16:50:15 -0300 (ADT) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by svr1.postgresql.org (Postfix) with ESMTP id 259E9D1B53D for ; Mon, 29 Sep 2003 16:50:13 -0300 (ADT) Received: from dellmobile (unknown[207.189.110.26]) by comcast.net (rwcrmhc12) with SMTP id <2003092919501401400eq7vqe> (Authid: ben.schneider@comcast.net); Mon, 29 Sep 2003 19:50:14 +0000 Reply-To: From: "Ben Schneider" To: Subject: Help with pivoting tables Date: Mon, 29 Sep 2003 12:50:20 -0700 Message-ID: <000c01c386c2$ea866700$5011a8c0@dellmobile> MIME-Version: 1.0 Content-Type: text/plain; charset="Windows-1252" Content-Transfer-Encoding: quoted-printable X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4510 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.9 tagged_above=0.0 required=5.0 tests=RCVD_IN_OSIRUSOFT_COM X-Spam-Level: X-Archive-Number: 200309/413 X-Sequence-Number: 15391 Hi, I am having some diffuculty with pivoting the results of a query. I am using the following SQL in an attempt to aggreate the data from a table. ------Begin Query------ SELECT groupid, activity_date,=20 count(CASE activity_subcode WHEN 100 THEN 1 ELSE NULL END) AS Attended,=20 count(CASE activity_subcode WHEN 101 THEN 1 ELSE NULL END) AS Unexcused, count(CASE activity_subcode WHEN 102 THEN 1 ELSE NULL END) AS Absent, count(CASE activity_subcode WHEN 103 THEN 1 ELSE NULL END) AS Called, count(*) AS total FROM activity WHERE activity_date BETWEEN '06/02/2003' AND '06/06/2003' GROUP BY groupid, activity_date, activity_subcode ORDER BY groupid, activity_date ------End Query------ The output is coming back like: Groupid activity_date attended unexcused absent called total --------------------------------------------------------------------- BNEIO 2003-06-04 7 0 0 0 7 BNEIO 2003-06-04 0 2 0 0 2 BNEIO 2003-06-05 4 0 0 0 4 BNEIO 2003-06-05 0 5 0 0 5 I need the output to come back with the groups_id and activity_date combined to look like this: Groupid activity_date attended unexcused absent called total --------------------------------------------------------------------- BNEIO 2003-06-04 7 2 0 0 9 BNEIO 2003-06-05 4 5 0 0 9 Any ideas? Thanks, Ben --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.521 / Virus Database: 319 - Release Date: 9/23/2003 =20