Re: Rows to columns query

From: Kris Jurka <books(at)ejurka(dot)com>
To: mike <mike(at)redtux1(dot)uklinux(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Rows to columns query
Date: 2004-05-10 18:59:59
Message-ID: Pine.BSO.4.56.0405101356460.30260@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 10 May 2004, mike wrote:

> Does anyone know if this is feasable
>
> I have two tables
>
> one has inv_id,amount,date, cheque no
>
> the second has
> inv_id, amount , code (this relate to type of expenditure)
>
> There is a one to many relationship on inv_id
>
> What I want to do is
>
> Group all the fields in the first table (easy), but then have the
> grouped values in the 2nd table appearing as values in the columns ie
>
> inv_id, cheque, amount_vote1,amount_vote2,amount_vote3 etc
>

See contrib/tablefunc's crosstab functions. You will need to know the
number of output columns in advance though.

Kris Jurka

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ron St-Pierre 2004-05-10 19:11:03 Re: nested elseif woes
Previous Message Kris Jurka 2004-05-10 18:56:39 Re: nested elseif woes