From: Carl van Tast <vanTast@Pivot.at>
To: pgsql-sql@postgresql.org
Subject: Re: group by weirdness
Date: Mon, 17 Sep 2001 20:07:39 +0200
Message-ID: <9decqt0vottpt0ju1i8re2mudhhhph24lr@4ax.com> (raw)
References: <3B9D72B6.5050600@selectacast.net>
<dv05qt02nk45ivsa80nhhhekk38efq0gqg@4ax.com>
On Sat, 15 Sep 2001 00:26:01 +0200, I wrote:
> [...]
>CREATE VIEW mj1 (jid, cnt) AS
>SELECT jid, COUNT(mid) cnt FROM mj GROUP BY jid;
This should be COUNT(mid) AS cnt ...
> [...]
>I did not test this with PostgreSQL, but you get the idea.
Well, now I did test with PostgreSQL (thanks, Jason Tishler, for your
Cygwin PostgreSQL README!). PG does not support column aliases without
"AS".
>Probably PG is even smart enough to handle it all in one:
Sure it is. So, Joseph, your solution is:
SELECT j.id, j.created, mj1.cnt, ml1.cnt, ml2.cnt
FROM j
LEFT JOIN (SELECT jid, COUNT(mid) AS cnt
FROM mj
GROUP BY jid) mj1
ON (j.id = mj1.jid)
LEFT JOIN (SELECT jid, COUNT(*) AS cnt
FROM ml
WHERE state <> 11
GROUP BY jid) ml1
ON (j.id = ml1.jid)
LEFT JOIN (SELECT jid, COUNT(*) AS cnt
FROM ml
WHERE state IN (2, 5)
GROUP BY jid) ml2
ON (j.id = ml2.jid)
WHERE j.fkey = 1;
HTH,
Carl van Tast
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: vanTast@Pivot.at
Subject: Re: group by weirdness
In-Reply-To: <9decqt0vottpt0ju1i8re2mudhhhph24lr@4ax.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox