Re: SQL (table transposition)

From: Volker Paul <vpaul(at)dohle(dot)com>
To: Dana(dot)Reed(at)clinicaldatacare(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: SQL (table transposition)
Date: 2000-08-04 07:30:26
Message-ID: 398A7112.E46D3E11@dohle.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dana(dot)Reed(at)clinicaldatacare(dot)com wrote:
>
> Is there any way to get table T3 (below) from T1 and T2 using SQL (select, view, etc)?
>
> T3 is basically all INDEX values from T1 matched to IND from T2 with the corresponding KEY/VALUE pairs transposed from rows to columns.
>
> -------
> |INDEX| (T1)
> -------
> | 1 |
> | 2 |
> | 3 |
> -------
>
> -----------------
> |IND|KEY| VALUE | (T2)
> -----------------
> | 1 | 1 | val_a |
> | 1 | 2 | val_b |
> | 1 | 3 | val_c |
> | 2 | 1 | val_d |
> | 2 | 2 | val_e |
> | 3 | 1 | val_f |
> | 3 | 3 | val_g |
> -----------------
>
> ----------------------------------
> |T1_INDEX|KEY1VAL|KEY2VAL|KEY3VAL| (T3)
> ----------------------------------
> | 1 | val_a | val_b | val_c |
> | 2 | val_d | val_e | |
> | 3 | val_f | | val_g |
> ----------------------------------
>

I think what you are looking for is cross tabulation,
TRANSFORM statement, but I don't know if that
is supported by PostgreSQL.

Volker Paul

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Sandis 2000-08-04 07:40:43 Re: Extracting data by months
Previous Message Daniel Kalchev 2000-08-04 05:53:50 Re: Extracting data by months