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

Поиск
Список
Период
Сортировка
От hubert depesz lubaczewski
Тема Re: GROUP BY on a column which might exist in one of two tables
Дата
Msg-id 20080625140926.GA17243@depesz.com
обсуждение исходный текст
Ответ на GROUP BY on a column which might exist in one of two tables  (Mark Stosberg <mark@summersault.com>)
Ответы Re: GROUP BY on a column which might exist in one of two tables  (Mark Stosberg <mark@summersault.com>)
Список pgsql-sql
On Wed, Jun 25, 2008 at 09:50:18AM -0400, Mark Stosberg wrote:
> 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


select   coalesce(h.partner_id, v.partner_id) as partner_id,   coalesce(v.count, 0) as total_views,   coalesce(h.count,
0)as total_hits
 
from   (select partner_id, count(*) from hits group by partner_id) as h   full outer join   (select partner_id,
count(*)from views group by partner_id) as v   on h.partner_id = v.partner_id
 
;

depesz


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

Предыдущее
От: Mark Stosberg
Дата:
Сообщение: GROUP BY on a column which might exist in one of two tables
Следующее
От: Mark Stosberg
Дата:
Сообщение: Re: GROUP BY on a column which might exist in one of two tables