From: PS PS <psus2020@yahoo.com>
To: pgsql-sql@postgresql.org
Subject: One-2-many relation - need distinct counts
Date: Tue, 26 Aug 2003 06:54:58 -0700 (PDT)
Message-ID: <20030826135458.83369.qmail@web20302.mail.yahoo.com> (raw)
Hi gurus,
I have table A, B and need a distinct count of
Accounts from A. There is a one-2-many relation
between A and B. Accounts # in A are all unique.
However, in B there will be duplicates. So the
problem I have is, when I join as follows:
Select Count(Distinct(account_no))
from A, B
where A.Account_no = B.Account_no
I get the correct count. If I do this:
Select Count(Distinct(account_no)), B.Account_type
from A, B
where A.Account_no = B.Account_no
group by B.Account_type
I get wrong counts because there some are duplicated.
I tried everything that I can think of - subquery, sub
table etc. I would appreciate some help in writing
the query. Thanks in advance.
PS
__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: psus2020@yahoo.com
Subject: Re: One-2-many relation - need distinct counts
In-Reply-To: <20030826135458.83369.qmail@web20302.mail.yahoo.com>
* 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