Re: counting distinct values - Mailing list pgsql-sql

From Bruce Momjian
Subject Re: counting distinct values
Date
Msg-id 200006080015.UAA04389@candle.pha.pa.us
Whole thread Raw
In response to counting distinct values  (Joseph Shraibman <jks@selectacast.net>)
List pgsql-sql
> 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,
Pennsylvania19026
 


pgsql-sql by date:

Previous
From: "Hiroshi Inoue"
Date:
Subject: RE: Problem with subquery in CHECK constraint.
Next
From: Kyle Bateman
Date:
Subject: References and privileges