Count equals 0

Поиск
Список
Период
Сортировка
От Rudi Starcevic
Тема Count equals 0
Дата
Msg-id 3E76BCB9.9070603@oasis.net.au
обсуждение исходный текст
Ответы Re: Count equals 0  (jasiek@klaster.net)
Re: Count equals 0  (greg@turnstep.com)
Re: Count equals 0  (Josh Berkus <josh@agliodbs.com>)
Список pgsql-sql
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.



В списке pgsql-sql по дате отправления:

Предыдущее
От: "Susan Hoddinott"
Дата:
Сообщение: Re: Create function statement with insert statement
Следующее
От: "Frankie Lam"
Дата:
Сообщение: PLPGSQL with Multibyte Issue