Search Postgresql Archives

Re: sub select as a data column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Phong & Ronni Bounmixay <bounmixay@xxxxxxxxx> writes:
> 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;

That doesn't really work in Oracle does it?  It violates the SQL spec
in at least three ways.  Try something like

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

(which should work in Oracle too, or any other SQL-spec-compliant
database).  Note the extra parentheses ... they're not optional.

			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux