From: Josh Berkus <josh@agliodbs.com>
To: Rudi Starcevic <rudi@oasis.net.au>
To: pgsql-sql@postgresql.org
Subject: Re: Count equals 0
Date: Tue, 18 Mar 2003 08:35:30 -0800
Message-ID: <200303180835.30399.josh@agliodbs.com> (raw)
In-Reply-To: <3E76BCB9.9070603@oasis.net.au>
References: <3E76BCB9.9070603@oasis.net.au>
Rudi,
> What I would like to see is something like:
>
> site a : 0
> site b : 3
> site c : 6
>
> I've tries Left outer join's with and without coalesce without joy so far.
> Please check out my query.
You're going to need to nest your query:
SELECT um2.site_name, COALESCE(count_um.total, 0) as total
FROM user_main um2 LEFT OUTER JOIN
(SELECT um.site_name, count(um.cus_id) AS total
FROM user_main um
WHERE NOT EXISTS
(
SELECT cus_id
FROM user_sys_messages usm
WHERE usm.cus_id = um.cus_id
)
GROUP BY um.site_name) count_um
ON um2.site_name = count_um.site_name
ORDER BY um2.site_name
--
Josh Berkus
Aglio Database Solutions
San Francisco
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: josh@agliodbs.com, rudi@oasis.net.au
Subject: Re: Count equals 0
In-Reply-To: <200303180835.30399.josh@agliodbs.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