Re: 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: Re: GROUP BY on a column which might exist in one of two tables
Date: 2008-06-25 14:17:55
Message-ID: 1214403475.30599.45.camel@localhost
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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!

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Greg Sabino Mullane 2008-06-25 14:20:53 Re: GROUP BY on a column which might exist in one of two tables
Previous Message hubert depesz lubaczewski 2008-06-25 14:09:26 Re: GROUP BY on a column which might exist in one of two tables