Received: from devel.nacs.net (devel.nacs.net [207.166.192.85]) by postgresql.org (Postfix) with ESMTP id 4B6164767BC for ; Fri, 19 Apr 2002 16:09:17 -0400 (EDT) Received: from nacs.net (tawny.nacs.net [207.166.192.127]) by devel.nacs.net (8.11.6/8.11.6) with ESMTP id g3JK95d02659 for ; Fri, 19 Apr 2002 16:09:05 -0400 Message-ID: <3CC07905.70701@nacs.net> Date: Fri, 19 Apr 2002 16:07:33 -0400 From: Brian Kosick User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:0.9.9) Gecko/20020311 X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Trying to get query to work Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-ECS-MailScanner: Found to be clean X-Archive-Number: 200204/255 X-Sequence-Number: 7519 Hello All, I apologize if I'm posting to the wrong place, if I should be posting somewhere else, I would appreciate it if someone would let me know, and accept my advance apologies. I have a table that looks like this: id | model | make | color | count ------------------------------------------------- 1 | Toyota | Corolla | Blue | 3 2 | Toyota | Corolla | Red | 2 3 | Dodge | Avenger | Black | 1 4 | Dodge | Avenger | Red | 5 6 | Chrysler | Sebring | Beige | 8 I need to create a SQL statement that will give me results that look like this: model | make | color | count | total | percentage ------------------------------------------------------------ Toyota | Corolla | Blue | 3 | 5 | 60% Toyota | Corolla | Red | 2 | 5 | 40% Dodge | Avenger | Black | 1 | 6 | 17% Dodge | Avenger | Red | 5 | 6 | 83% Chrysler | Sebring | Beige | 8 | 8 | 100% This is the closest that I've come so far: SELECT model, make, color, SUM(count) AS total, ((count/SUM(count))*100) AS percentage FROM autos GROUP BY model, make, color, count; However this produces a table that looks like this: model | make | color | count | total | percentage ------------------------------------------------------------ Toyota | Corolla | Blue | 3 | 3 | 100% Toyota | Corolla | Red | 2 | 2 | 100% Dodge | Avenger | Black | 1 | 1 | 100% Dodge | Avenger | Red | 5 | 5 | 100% Chrysler | Sebring | Beige | 8 | 8 | 100%