Re: pesky select query

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Ingram, Bryan" <BIngram(at)sixtyfootspider(dot)com>
Cc: "'pgsql-sql(at)postgresql(dot)org'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: pesky select query
Date: 2000-10-03 23:37:44
Message-ID: 1954.970616264@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Ingram, Bryan" <BIngram(at)sixtyfootspider(dot)com> writes:
> What I'd like to do is produce a query that will
> list each app_code and the count of distinct states for that app_code on one
> line. I don't care what the state_code is, I just need to know the number
> of distinct state_codes per app_code.

> So far I've tried variations of select distincts with counts() and group
> by's on various fields. I briefly considered trying to do this with an
> outer join, but I'm not sure it'd work. I'm still using 6.5.x so I'd have to
> simulate it with a union all/subquery. For that reason I thought'd I'd ask
> here first to see if there is a better way.

Update to 7.0.* and do
select app_code, count(distinct state_code) from tab group by app_code;

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Mount 2000-10-03 23:56:55 RE: Object features of pg
Previous Message Ingram, Bryan 2000-10-03 20:47:44 pesky select query