MySQL include count 不返回计数为零的行
我有以下 MySQL 代码:
SELECT COUNT(e.eid) AS cnt, e.c_id, c.cdesc
FROM e
JOIN c on c.c_id = e.c_id
GROUP by c.c_id
不幸的是 count
没有考虑 0
的行,因此例如 c_id 可能有 10 行,但只显示 9 行(因为一个e_id
的计数为零)。
我尝试了 LEFT JOIN 和 RIGHT JOIN ,但都没有成功。有人还有其他建议吗?
I have the following MySQL code:
SELECT COUNT(e.eid) AS cnt, e.c_id, c.cdesc
FROM e
JOIN c on c.c_id = e.c_id
GROUP by c.c_id
Unfortunately the count
does not take into account rows which are 0
, so for example c_id may have 10 rows but only 9 are displayed (because one of the e_id
's count is zero).
I have tried both LEFT JOIN
and RIGHT JOIN
with no success. Does anyone have any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑你需要的是这样的:
I suspect that what you need is this:
使用:
Use: