Skip site navigation (1) Skip section navigation (2)

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 (view raw or flat)
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

pgsql-sql by date

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

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group