Calculating Percentages - Mailing list pgsql-sql

From David Siegal
Subject Calculating Percentages
Date
Msg-id Pine.LNX.4.44.0305081102100.30051-100000@brave.cs.uml.edu
Whole thread Raw
Responses Re: Calculating Percentages
Re: Calculating Percentages
List 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



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Ok, how do I debug THIS?
Next
From: Jon Earle
Date:
Subject: Re: [GENERAL] PostgreSQL Qs