X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 62D00D1ED0D for ; Fri, 7 May 2004 05:01:08 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 49664-08 for ; Fri, 7 May 2004 05:00:49 -0300 (ADT) Received: from anchor-post-30.mail.demon.net (anchor-post-30.mail.demon.net [194.217.242.88]) by svr1.postgresql.org (Postfix) with ESMTP id B15A1D1F33C for ; Fri, 7 May 2004 05:00:47 -0300 (ADT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-30.mail.demon.net with esmtp (Exim 3.35 #1) id 1BM0Hn-0005sV-0U; Fri, 07 May 2004 09:00:48 +0100 Received: from [192.168.1.17] (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id 471B5167FE; Fri, 7 May 2004 09:00:44 +0100 (BST) Message-ID: <409B422B.6080502@archonet.com> Date: Fri, 07 May 2004 09:00:43 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 0.6 (X11/20040502) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Martin Kuria Cc: olly@lfix.co.uk, middink@indo.net.id, pgsql-sql@postgresql.org Subject: Re: SUM() & GROUP BY References: In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/63 X-Sequence-Number: 17777 Martin Kuria wrote: > Hi again I have two tables I would like to query i.e. service table and > division table > > SELECT s.pd_geo, COUNT(s.pd_geo) FROM ser s GROUP BY s.pd_geo; > OUTPUT: > pd_geo | count > ---------------------- > 1 | 49 > 2 | 39 > 3 | 6 > 4 | 54 > > SELECT d.divisions_name, d.divisions_id) > FROM ser s, ser_divisions d > WHERE d.divisions_id = s.ser_divisions; > > division_name | divisions_id > -------------------------------------- > DEC | 6 > DEPI | 7 > DRC | 8 > > How can I create a query that displays How the divisions answered the > question please do assist. Martin - you'll need to explain exactly what you want. Can you show what outputs you would like given the above data? -- Richard Huxton Archonet Ltd