pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ingram, Bryan <BIngram@sixtyfootspider.com>
Cc: 'pgsql-sql@postgresql.org' <pgsql-sql@postgresql.org>
Subject: Re: pesky select query
Date: Tue, 03 Oct 2000 19:37:44 -0400
Message-ID: <1954.970616264@sss.pgh.pa.us> (raw)
In-Reply-To: <01CCE949D2717845BA2E573DC081167E052F42@BKMAIL.sfsinternal.com>
References: <01CCE949D2717845BA2E573DC081167E052F42@BKMAIL.sfsinternal.com>

"Ingram, Bryan" <BIngram@sixtyfootspider.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



view thread (2+ messages)

Message-ID: <1954.970616264@sss.pgh.pa.us>
Permalink:  ../1954.970616264@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1954.970616264@sss.pgh.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: tgl@sss.pgh.pa.us, BIngram@sixtyfootspider.com
  Subject: Re: pesky select query
  In-Reply-To: <1954.970616264@sss.pgh.pa.us>
  References: <01CCE949D2717845BA2E573DC081167E052F42@BKMAIL.sfsinternal.com> <1954.970616264@sss.pgh.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