Percentages? - Mailing list pgsql-sql

From Chris Bitmead
Subject Percentages?
Date
Msg-id 3721B398.DF32C1EC@bigfoot.com
Whole thread Raw
In response to Finding the "most recent" rows  (Julian Scarfe <jas1@scigen.co.uk>)
List pgsql-sql
How to calculate percentages? What is the correct SQL?

CREATE TABLE poll (candidate text, votes int4);

I want to do something like (this is wrong)...
SELECT candidate, votes, (votes / sum(votes)) * 100) AS percent FROM
poll;

Fred Smith  |  500 | 25
Bill Bloggs | 1000 | 50
Jim Jones   |  500 | 25


-- 
Chris Bitmead
http://www.bigfoot.com/~chris.bitmead
mailto:chris.bitmead@bigfoot.com


pgsql-sql by date:

Previous
From: Chris Bitmead
Date:
Subject: Re: [SQL] Large objects - bug? caveat? feature?
Next
From: Chris Bitmead
Date:
Subject: Confusion about DISTINCT.