Received: from candle.pha.pa.us (root@s5-03.ppp.op.net [209.152.195.67]) by hub.org (8.10.1/8.10.1) with ESMTP id e580VMc65978 for ; Wed, 7 Jun 2000 20:31:22 -0400 (EDT) Received: (from pgman@localhost) by candle.pha.pa.us (8.9.0/8.9.0) id UAA04389; Wed, 7 Jun 2000 20:15:58 -0400 (EDT) From: Bruce Momjian Message-Id: <200006080015.UAA04389@candle.pha.pa.us> Subject: Re: counting distinct values In-Reply-To: <393EE030.C4F9897E@selectacast.net> "from Joseph Shraibman at Jun 7, 2000 07:52:16 pm" To: Joseph Shraibman Date: Wed, 7 Jun 2000 20:15:58 -0400 (EDT) CC: "pgsql-sql@postgresql.org" X-Mailer: ELM [version 2.4ME+ PL77 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Archive-Number: 200006/79 > Using the example from > http://www.postgresql.org/docs/aw_pgsql_book/node59.html, what would I > do if I wanted to know the number of different cities where I had a > friend in each state? select count(city) group by state; would not work > because if you had two friends in the same city it would be counted > twice. > How about? select city, state, count(*) group by state, city; -- Bruce Momjian | http://www.op.net/~candle pgman@candle.pha.pa.us | (610) 853-3000 + If your life is a hard drive, | 830 Blythe Avenue + Christ can be your backup. | Drexel Hill, Pennsylvania 19026