MySql计数不能显示0值 [英] MySql Count cannot show 0 values
问题描述
我有两个表一个
员工和邮件订阅
员工看起来像这样:
I have two tables one Employee and mailing Subscriptions Employee looks like this:
Name(pk)|姓|年龄
Name (pk) | Surname | Age
邮寄订阅
MailId EmployeeName(fk)|说明|日期
MailId (pk)| EmployeeName (fk)|Description | Date
我想要每个客户的订阅号码,因此我尝试了以下查询:
I wanted to subscription number for each customer, therefore I tried the following query:
Select COUNT(c.Name)
From Employee
INNER JOIN mailingSubscriptions as m ON c.Name = m.EmployeeName;
它会给每个雇员的所有计数
It will give me all counts for each Employee that has an entry in the mailing subscription.
我的问题是,我想查看所有员工的计数,包括没有条目的计数(因此显示0),我试过外左/右连接,但它不工作。我做错了什么?
My problem is that I want to see the counts for ALL the Employees, including the ones without an entry (therefore to show 0), I tried an outer left/right join, but it will not work. Am I doing something wrong?
推荐答案
SELECT c.name, count(m.mailid)
FROM Employee
LEFT JOIN mailingSubscriptions as m ON c.Name = m.EmployeeName
GROUP BY c.name;
这篇关于MySql计数不能显示0值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!