SQL 帮助 - 计算两个表中的行数
我有 2 个表:产品和产品。类别
我正在尝试编写 sql 来计算每个类别的产品数量。到目前为止,我有这个:
SELECT `name`, count(*) as `size`
FROM products
INNER JOIN category ON category.`id` = products.`categoryID`
GROUP BY category.`name`
这将返回每个类别名称的列表以及该类别的产品数量。但是,它没有列出包含 0 个产品的类别。我该如何解决这个问题?
I have 2 tables: products & category
I'm trying to write the sql to count the number of products per category. So far I have this:
SELECT `name`, count(*) as `size`
FROM products
INNER JOIN category ON category.`id` = products.`categoryID`
GROUP BY category.`name`
This will return me a list of each category name and the number of products for that category. However it doesn't list categories that have 0 products. How do I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用右连接。
Use a right join.
尝试使用:
Try with: