pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Witham <davidw@unidial.com.au>
To: pgsql-sql@postgresql.org
Subject: Transpose rows to columns
Date: Tue, 13 Jan 2004 12:12:52 +1100
Message-ID: <CFA248776934FD43847E740E43C346D199DB64@ozimelb03.ozicom.com> (raw)

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




view thread (4+ messages)  latest in thread

Message-ID: <CFA248776934FD43847E740E43C346D199DB64@ozimelb03.ozicom.com>
Permalink:  ../CFA248776934FD43847E740E43C346D199DB64@ozimelb03.ozicom.com/
Also on:    postgresql.org/message-id/CFA248776934FD43847E740E43C346D199DB64@ozimelb03.ozicom.com

 · 

reply

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: davidw@unidial.com.au
  Subject: Re: Transpose rows to columns
  In-Reply-To: <CFA248776934FD43847E740E43C346D199DB64@ozimelb03.ozicom.com>

* 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