X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 4B5C39FB1F0 for ; Tue, 19 Sep 2006 12:11:14 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 90166-09 for ; Tue, 19 Sep 2006 15:10:42 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail.telefor.hu (mail.telefor.hu [193.68.53.97]) by postgresql.org (Postfix) with ESMTP id E77ED9FB2A1 for ; Tue, 19 Sep 2006 12:09:40 -0300 (ADT) Received: from telefor-server.int.telefor-new.hu (telefor-server.int.telefor-new.hu [10.0.20.100]) by mail.telefor.hu (Postfix) with ESMTP id D1AE61C044; Tue, 19 Sep 2006 17:09:35 +0200 (CEST) Received: from [10.0.20.33] ([10.0.20.33]) by telefor-server.int.telefor-new.hu with Microsoft SMTPSVC(6.0.3790.1830); Tue, 19 Sep 2006 17:09:35 +0200 Message-ID: <4510082F.203@telefor.hu> Date: Tue, 19 Sep 2006 17:09:35 +0200 From: =?UTF-8?B?TWV6ZWkgWm9sdMOhbg==?= Organization: Telefor Kft. User-Agent: Thunderbird 1.5.0.5 (Windows/20060719) MIME-Version: 1.0 To: Ezequias Rodrigues da Rocha CC: pgsql-sql@postgresql.org Subject: Re: Count and list only where count is bigger than 1 References: <55c095e90609190804w1eaac2aanc660020995d3710a@mail.gmail.com> In-Reply-To: <55c095e90609190804w1eaac2aanc660020995d3710a@mail.gmail.com> Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Sep 2006 15:09:35.0715 (UTC) FILETIME=[9E633B30:01C6DBFD] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.136 tagged_above=0 required=5 tests=HTML_50_60, HTML_MESSAGE, MIME_HTML_ONLY, UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200609/127 X-Sequence-Number: 26338 Ezequias Rodrigues da Rocha wrote:
SELECT distinct cli.bairro, COUNT( * ) as qtd
FROM base.cliente cli
GROUP BY cli.cidade, cli.bairro
ORDER BY 2

I noticed that I cannot use "where qtd > 1" ok ?

What to do ?
Google/read tutorial for HAVING. E.g.

SELECT distinct cli.bairro, COUNT( * ) as qtd
FROM base.cliente cli
GROUP BY cli.cidade, cli.bairro
HAVING COUNT(*) > 1

Zizi