pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rudi Starcevic <rudi@oasis.net.au>
To: pgsql-sql@postgresql.org
Subject: Count equals 0
Date: Tue, 18 Mar 2003 16:29:13 +1000
Message-ID: <3E76BCB9.9070603@oasis.net.au> (raw)

Greetings,

I have what I think is an easy query but is not working out for me.
So I thought I'd ask ..


I have 2 tables :

user_main
user_sys_messages

In user_main I have many user's which belong to 3 web sites.
In my admin tool I can send a user an email message and that message is 
logged to the user_sys_messages table.

All that is good.
What I want to report is those who have *not* recieved any email from me.
If each of the 3 web site's has a user in user_main who has not recieved 
any messages the report form the below query
looks like

site a : 1
site b : 3
site c : 6

My problem is if a site has no one that has not recieved any message 
they do not appear in the report.
Ie.

site b : 3
site c : 6

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.

Thank you kindly.

-- new members --- members who haven't recieved any email from us
    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
    ORDER BY um.site_name

Regards
Rudi.




view thread (5+ messages)  latest in thread

Message-ID: <3E76BCB9.9070603@oasis.net.au>
Permalink:  ../3E76BCB9.9070603@oasis.net.au/
Also on:    postgresql.org/message-id/3E76BCB9.9070603@oasis.net.au

 · 

reply

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: rudi@oasis.net.au
  Subject: Re: Count equals 0
  In-Reply-To: <3E76BCB9.9070603@oasis.net.au>

* 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