pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCross joining table with itself
2+ messages / 2 participants
[nested] [flat]
* Cross joining table with itself
@ 2003-09-21 14:38 Bob Hutzel <tidal7@myrealbox.com>
0 siblings, 1 reply; 2+ messages in thread
From: Bob Hutzel @ 2003-09-21 14:38 UTC (permalink / raw)
To: pgsql-sql
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Cross joining table with itself
@ 2003-09-22 01:12 Bruno Wolff III <bruno@wolff.to>
parent: Bob Hutzel <tidal7@myrealbox.com>
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Wolff III @ 2003-09-22 01:12 UTC (permalink / raw)
To: Bob Hutzel <tidal7@myrealbox.com>; +Cc: pgsql-sql
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-09-22 01:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-09-21 14:38 Cross joining table with itself Bob Hutzel <tidal7@myrealbox.com>
2003-09-22 01:12 ` Bruno Wolff III <bruno@wolff.to>
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