MySql 计数无法显示 0 值

发布于 2024-10-27 03:58:04 字数 389 浏览 3 评论 0原文

我有两张桌子,一张 员工和邮件订阅 员工看起来像这样:

姓名(pk)|姓氏 | 邮寄年龄

订阅

MailId (pk)|员工姓名(外籍)|描述| 日期

我想要每个客户的订阅号的

Select COUNT(c.Name) 
From Employee 
    INNER JOIN mailingSubscriptions as m ON c.Name = m.EmployeeName;

,因此我尝试了以下查询:它将为我提供在邮件订阅中拥有条目的每个员工的所有计数。

我的问题是我想查看所有员工的计数,包括那些没有条目的员工(因此显示 0),我尝试了外部左/右连接,但它不起作用。我做错了什么吗?

I have two tables one
Employee and mailing Subscriptions
Employee looks like this:

Name (pk) | Surname | Age

mailing Subsriptions

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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-11-03 03:58:04
SELECT c.name, count(m.mailid)
FROM Employee 
   LEFT JOIN mailingSubscriptions as m ON c.Name = m.EmployeeName
GROUP BY c.name;
SELECT c.name, count(m.mailid)
FROM Employee 
   LEFT JOIN mailingSubscriptions as m ON c.Name = m.EmployeeName
GROUP BY c.name;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文