Re: Joins with aggregate data

From: Paul McGarry <paul(dot)mcgarry(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Joins with aggregate data
Date: 2005-07-08 03:37:54
Message-ID: a056b1d405070720371835dbf4@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you Michael, your suggestion works a charm (though I didn't
bother coalescing the two grp because I think the USING takes care of
that anyway.

Paul

On 7/8/05, Michael Fuhr <mike(at)fuhr(dot)org> wrote:

> SELECT coalesce(g.grp, b.grp) AS grp,
> coalesce(g.count, 0) AS countgood,
> coalesce(g.sum, 0) AS sumgood,
> coalesce(b.count, 0) AS countbad,
> coalesce(b.sum, 0) AS sumbad
> FROM
> (SELECT grp, count(good), sum(good) FROM lefty GROUP BY grp) AS g
> FULL OUTER JOIN
> (SELECT grp, count(bad), sum(bad) FROM righty GROUP BY grp) AS b USING (grp);

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-07-08 03:52:49 Re: index bloat
Previous Message Michael Fuhr 2005-07-08 02:56:48 Re: Joins with aggregate data