Re: GROUP BY on a column which might exist in one of two tables - Mailing list pgsql-sql

From Mark Stosberg
Subject Re: GROUP BY on a column which might exist in one of two tables
Date
Msg-id 1214403475.30599.45.camel@localhost
Whole thread Raw
In response to Re: GROUP BY on a column which might exist in one of two tables  (hubert depesz lubaczewski <depesz@depesz.com>)
List pgsql-sql
> 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
> ;
> 

That looks right. Thanks!




pgsql-sql by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: GROUP BY on a column which might exist in one of two tables
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: GROUP BY on a column which might exist in one of two tables