Transposing data

From: Hans-Jürgen Schönig <hs(at)cybertec(dot)at>
To: pgsql-sql(at)postgresql(dot)org
Subject: Transposing data
Date: 2001-05-20 19:42:37
Message-ID: 3B081E2D.BB24DBE3@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tubagus Nizomi 2001-05-21 02:56:57 Set Datestyle
Previous Message Hans-Jürgen Schönig 2001-05-20 19:34:39 PL/pgSQL problem with variables