pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Siegal <dsiegal@brave.cs.uml.edu>
Cc: pgsql-sql@postgresql.org
Subject: Re: Calculating Percentages
Date: Wed, 14 May 2003 11:23:39 -0400
Message-ID: <24226.1052925819@sss.pgh.pa.us> (raw)
In-Reply-To: <Pine.LNX.4.44.0305081102100.30051-100000@brave.cs.uml.edu>
References: <Pine.LNX.4.44.0305081102100.30051-100000@brave.cs.uml.edu>

David Siegal <dsiegal@brave.cs.uml.edu> writes:
> If I were to do:

> SELECT nationality, ((COUNT(*) * 100)/(select count(*) from member)) as
> percentage FROM member GROUP BY nationality ORDER BY nationality;

> would this repeatedly execute the inner query over and over?

No, it'd do it just once, because the sub-select has no dependency on
the outer select.  (If the sub-select used any variables from the outer
level, then it'd have to be done over at each outer row.)

You can tell the difference between these cases by looking at EXPLAIN
output for the query: do-once sub-selects are labeled InitPlans,
do-every-time sub-selects are labeled SubPlans.

			regards, tom lane



view thread (13+ messages)  latest in thread

Message-ID: <24226.1052925819@sss.pgh.pa.us>
Permalink:  ../24226.1052925819@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24226.1052925819@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, dsiegal@brave.cs.uml.edu
  Subject: Re: Calculating Percentages
  In-Reply-To: <24226.1052925819@sss.pgh.pa.us>

* 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