GROUP BY on a column which might exist in one of two tables

From: Mark Stosberg <mark(at)summersault(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: GROUP BY on a column which might exist in one of two tables
Date: 2008-06-25 13:50:18
Message-ID: 1214401817.30599.40.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Hello,

I could use some help figuring out a complex "GROUP BY".
As a setup, let's say I have two tables which stores a single "hit" or
"view" in a row

hits
hit_id
partner_id

views
view_id
partner_id

There is of course a "partners" table with a "partner_id" column.

My target result is more like

partner_id
total_views
total_hits

Where the totals are "counts" of the the rows in the hits and views
tables. There should be no rows for partners without hits or views.

My first attempt at the SQL for this GROUP
COALESCE(hits.partner_id,views.partner_id) which didn't work.

I'm stuck on what to try next.

Thanks!

Mark

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message hubert depesz lubaczewski 2008-06-25 14:09:26 Re: GROUP BY on a column which might exist in one of two tables
Previous Message Allan Kamau 2008-06-25 11:11:10 Re: Sequential event query