X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 64D5ED1B499 for ; Tue, 13 Jan 2004 01:13:25 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 11416-03 for ; Mon, 12 Jan 2004 21:12:54 -0400 (AST) Received: from ozimelb03.ozicom.com (unknown [203.185.247.100]) by svr1.postgresql.org (Postfix) with ESMTP id DFB91D1B449 for ; Mon, 12 Jan 2004 21:12:49 -0400 (AST) content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Subject: Transpose rows to columns Content-Transfer-Encoding: quoted-printable X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 Date: Tue, 13 Jan 2004 12:12:52 +1100 Message-ID: X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Transpose rows to columns Thread-Index: AcPZcl5OqAScKXXEThOL94BrOwfjcg== From: "David Witham" To: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/100 X-Sequence-Number: 16493 Hi, I have a query that returns data like this: cust_id cust_name month cost revenue margin 991234 ABC 2003-07-01 10 15 5 991234 ABC 2003-08-01 11 17 6 991234 ABC 2003-09-01 12 19 7 991235 XYZ 2003-07-01 13 21 8 991235 XYZ 2003-08-01 12 19 7 991235 XYZ 2003-09-01 11 17 6 I want to turn it around so it displays like this: 991234,ABC,2003-07-01,10,15,5,2003-08-01,11,17,6,2003-09-01,12,19,7 991235,XYZ,2003-07-01,13,21,8,2003-08-01,12,19,7,2003-09-01,11,17,6 (I've used commas to shorten the layout for the example) Does anyone have some ideas on how to do this? Thanks, David Witham Telephony Platforms Architect Unidial Ph: 03 8628 3383 Fax: 03 8628 3399