pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Mueller <brunomueller@gmx.net>
To: pgsql-sql@postgresql.org
Subject: refer to computed columns
Date: Tue, 24 Aug 2004 17:10:11 +0200
Message-ID: <cgflp3$k7a$1@news.hub.org> (raw)

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




Message-ID: <cgflp3$k7a$1@news.hub.org>
Permalink:  ../cgflp3$k7a$1@news.hub.org/
Also on:    postgresql.org/message-id/cgflp3$k7a$1@news.hub.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: brunomueller@gmx.net
  Subject: Re: refer to computed columns
  In-Reply-To: <cgflp3$k7a$1@news.hub.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox