Calculating Percentages

From: David Siegal <dsiegal(at)brave(dot)cs(dot)uml(dot)edu>
To: pgsql-sql(at)postgresql(dot)org
Subject: Calculating Percentages
Date: 2003-05-08 15:02:53
Message-ID: Pine.LNX.4.44.0305081102100.30051-100000@brave.cs.uml.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have 'member' table with a 'nationality' column. I want to get the
percentage breakdown of members by nationality, e.g.

American 29%
Canadian 14%
Mexican 11%
...

Is there an efficient way to do this is a single query?

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?

Thanks!
David

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2003-05-08 15:05:57 Re: seeing type defination..
Previous Message mallah 2003-05-08 15:02:39 Re: seeing type defination..