Percentages?

From: Chris Bitmead <chris(dot)bitmead(at)bigfoot(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgreSQL(dot)org>
Subject: Percentages?
Date: 1999-04-24 12:05:44
Message-ID: 3721B398.DF32C1EC@bigfoot.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)bitmead(at)bigfoot(dot)com

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Nigel Tamplin 1999-04-25 08:10:07 Relating 1 table to another.
Previous Message Chris Bitmead 1999-04-24 02:58:53 Re: [SQL] Large objects - bug? caveat? feature?