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

Поиск
Список
Период
Сортировка
От Mark Stosberg
Тема GROUP BY on a column which might exist in one of two tables
Дата
Msg-id 1214401817.30599.40.camel@localhost
обсуждение исходный текст
Ответы Re: GROUP BY on a column which might exist in one of two tables  (hubert depesz lubaczewski <depesz@depesz.com>)
Re: GROUP BY on a column which might exist in one of two tables  ("Greg Sabino Mullane" <greg@turnstep.com>)
Список 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






В списке pgsql-sql по дате отправления:

Предыдущее
От: Allan Kamau
Дата:
Сообщение: Re: Sequential event query
Следующее
От: hubert depesz lubaczewski
Дата:
Сообщение: Re: GROUP BY on a column which might exist in one of two tables