| From: | Bruno Mueller <brunomueller(at)gmx(dot)net> |
|---|---|
| To: | pgsql-sql(at)postgresql(dot)org |
| Subject: | refer to computed columns |
| Date: | 2004-08-24 15:10:11 |
| Message-ID: | cgflp3$k7a$1@news.hub.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
Hi
Think of the following query:
1 select
2 country,
3 (select sum(salary) from employees) as totalSalary,
4 sum(salary) as countrySalary,
5 countrySalary / totalSalary as countryPct
6 from employees
7 group by country
8 order by country
;
I know it does not work, but is there a way to refer to
the "computed" columns in line 5, so that I do not have
to repeat the calculations again.
BTW, are the calculation done more then once if I specify
1 select
2 country,
3 (select sum(salary) from employees) as totalSalary,
4 sum(salary) as countrySalary,
5 sum(salary) / (select sum(salary) from employees) as countryPct
6 from employees
7 group by country
8 order by country
;
Thanks for the help
Bruno
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Josh Berkus | 2004-08-24 19:52:30 | Re: Possible rounding error of large float values? |
| Previous Message | Bruce Momjian | 2004-08-24 11:20:39 | Re: Disable trigger with Postgresql 7.4.x? |