pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: counting distinct values
Date: Wed, 7 Jun 2000 20:15:58 -0400 (EDT)
Message-ID: <200006080015.UAA04389@candle.pha.pa.us> (raw)
In-Reply-To: <393EE030.C4F9897E@selectacast.net>

> 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



view thread (5+ messages)  latest in thread

Message-ID: <200006080015.UAA04389@candle.pha.pa.us>
Permalink:  ../200006080015.UAA04389@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200006080015.UAA04389@candle.pha.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, jks@selectacast.net
  Subject: Re: counting distinct values
  In-Reply-To: <200006080015.UAA04389@candle.pha.pa.us>
  References: <393EE030.C4F9897E@selectacast.net> <200006080015.UAA04389@candle.pha.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox