Re: sub select as a data column

From: "Jim Buttafuoco" <jim(at)contactbda(dot)com>
To: Phong & Ronni Bounmixay <bounmixay(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: sub select as a data column
Date: 2005-11-28 21:38:52
Message-ID: 20051128213746.M23573@contactbda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

you were close, try the following (untesting). You need the alias on the outer my_table for this to work

select year report_year,
sum(amount),
sum(select amount from my_table where year <= a.year)
from my_table a
group by report_year;

---------- Original Message -----------
From: Phong & Ronni Bounmixay <bounmixay(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Sent: Mon, 28 Nov 2005 13:18:41 -0700
Subject: [GENERAL] sub select as a data column

> I am having trouble coming up with words to describe exactly what I need so
> searching for a solution is getting frustrating! If this has been answered
> twelve hundred times - please forgive me!
>
> I want to do in postgresql what I do in oracle:
>
> select year report_year,
> sum(amount),
> sum(select amount from my_table where year <= report_year)
> from my_table
> group by report_year;
>
> I see lots of stuff on subselect in the from clause - but how do you
> subselect as a data column?
>
> Thanks for the help - it is SEVERLY appreciated!
> Ronni
------- End of Original Message -------

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-11-28 21:47:34 Re: sub select as a data column
Previous Message Tom Lane 2005-11-28 21:36:06 Re: problem with psql?