pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hans-Jürgen Schönig <hs@cybertec.at>
To: pgsql-sql@postgresql.org
Subject: Transposing data
Date: Sun, 20 May 2001 21:42:37 +0200
Message-ID: <3B081E2D.BB24DBE3@cybertec.at> (raw)

I want the values in column label to be displayed in the a-axis. Is
there an easy way to transform the data:
Here is the input data:
 age_code | label | count
----------+-------+-------
 age_1    | 30k   |     1
 age_1    | 50k   |     2
 age_1    | more  |     2
 age_2    | 40k   |     2
 age_3    | 40k   |     1

I want the result to be:

age_code | 30k | 40k | 50k  | more
-----------------------
age_1       | 1      |         |    2   | 1
age_2       |         |      2 |
age_3       |          |     1 |         |

Is there any easy way to do the job or do I have to write a PL/pgSQL
function?

    Hans




view thread (3+ messages)  latest in thread

Message-ID: <3B081E2D.BB24DBE3@cybertec.at>
Permalink:  ../3B081E2D.BB24DBE3@cybertec.at/
Also on:    postgresql.org/message-id/3B081E2D.BB24DBE3@cybertec.at

 · 

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: hs@cybertec.at
  Subject: Re: Transposing data
  In-Reply-To: <3B081E2D.BB24DBE3@cybertec.at>

* 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