Received: from trends.net (root@clio.trends.ca [209.47.148.2]) by hub.org (8.9.3/8.9.1) with ESMTP id MAA02095 for ; Sat, 24 Apr 1999 12:12:46 -0400 (EDT) (envelope-from chris.bitmead@bigfoot.com) Received: from tech.com.au (root@techpt.lnk.telstra.net [139.130.75.122]) by trends.net (8.8.8/8.8.8) with ESMTP id IAA15942 for ; Sat, 24 Apr 1999 08:06:10 -0400 (EDT) Received: from bigfoot.com (chris@localhost [127.0.0.1]) by tech.com.au (8.8.7/8.8.7) with ESMTP id WAA17302 for ; Sat, 24 Apr 1999 22:05:47 +1000 Sender: chris@tech.com.au Message-ID: <3721B398.DF32C1EC@bigfoot.com> Date: Sat, 24 Apr 1999 12:05:44 +0000 From: Chris Bitmead X-Mailer: Mozilla 4.51 [en] (X11; I; Linux 2.0.36 i686) X-Accept-Language: en MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: Percentages? References: <371F2ED6.29FD9251@scigen.co.uk> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit 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