X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BF41D9DCA9F for ; Sun, 4 Dec 2005 17:33:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 22775-06 for ; Sun, 4 Dec 2005 17:33:54 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by postgresql.org (Postfix) with ESMTP id 0E52C9DCAA9 for ; Sun, 4 Dec 2005 17:33:54 -0400 (AST) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id C81473507B; Sun, 4 Dec 2005 13:33:56 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id C629A35017; Sun, 4 Dec 2005 13:33:56 -0800 (PST) Date: Sun, 4 Dec 2005 13:33:56 -0800 (PST) From: Stephan Szabo To: Joost Kraaijeveld Cc: "Pgsql-sql@postgresql.org" Subject: Re: How to get a count() where column < ''? In-Reply-To: <1133730772.5560.8.camel@Panoramix> Message-ID: <20051204133233.O57404@megazone.bigpanda.com> References: <1133730772.5560.8.camel@Panoramix> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200512/18 X-Sequence-Number: 23560 On Sun, 4 Dec 2005, Joost Kraaijeveld wrote: > Hi, > > I want the number of customers that have a zipCode smaller tha a given > value. The foolowing query doe snot work : I get an error (ERROR: > column "addresses.zipcode" must appear in the GROUP BY clause or be used > in an aggregate function) and I do not know how to solve it. > > SELECT COUNT(customers.objectid) FROM prototype.customers, > prototype.addresses > WHERE > customers.contactaddress = addresses.objectid > AND > zipCode < '2716BN' > ORDER By zipCode, houseNumber > > Anyone an idea? In a non-grouped query like the above, I don't think that the order by is meaningful. You only get one row back anyway without a group by, and there's no single zipCode or houseNumber to associate with the row.