From: Bruno Wolff III <bruno@wolff.to>
To: Bob Hutzel <tidal7@myrealbox.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Cross joining table with itself
Date: Sun, 21 Sep 2003 20:12:30 -0500
Message-ID: <20030922011230.GA9968@wolff.to> (raw)
In-Reply-To: <pan.2003.09.21.14.33.57.361582@myrealbox.com>
References: <pan.2003.09.21.14.33.57.361582@myrealbox.com>
On Sun, Sep 21, 2003 at 14:38:23 +0000,
Bob Hutzel <tidal7@myrealbox.com> wrote:
> I've been stumped trying to solve this problem via SQL. I have a table ID,
> member1, member2, member3. In any row, any member field may have a value
> or be null. I want to tally up how many times each member appears in the
> table as a whole. For example, if two entries were ('a', '', 'c') and
> ('b', 'c', ''), I'd like my final result to be:
>
> a, 1
> b, 1
> c, 2
>
> Is this feasible? Thank you for any help.
You can 'union all' selects of each of the three columns where the appropiate
member value is not null and use group by and count on the result.
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: bruno@wolff.to, tidal7@myrealbox.com
Subject: Re: Cross joining table with itself
In-Reply-To: <20030922011230.GA9968@wolff.to>
* 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