Mysql查询总和和分组不显示具有空值的行
我有以下查询:
SELECT Customer, SUM(SoldUnits) AS SoldUnits
FROM Uploads
WHERE Year = 2021
AND Week = 11
GROUP BY Customer;
并返回:
Customer | SoldUnits |
---|---|
CUSTOMER A | 55 |
CUSTOMER B | 32 |
CUSTOMER D | 17 |
CUSTOMER C
存在,但没有 week 11
的数据并且我想显示带有 0 个 SoldUnits
的 CUSTOMER C
。我怎样才能做到这一点?
I have this query:
SELECT Customer, SUM(SoldUnits) AS SoldUnits
FROM Uploads
WHERE Year = 2021
AND Week = 11
GROUP BY Customer;
And Returns me:
Customer | SoldUnits |
---|---|
CUSTOMER A | 55 |
CUSTOMER B | 32 |
CUSTOMER D | 17 |
CUSTOMER C
exist, but it doesn't have data for the week 11
and I want to show CUSTOMER C
with 0 SoldUnits
. How Can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您的表确实包含您希望在报告中显示的所有客户,您可以进行条件求和并删除
WHERE
子句:Assuming your table does have all customers you want to appear in the report, you could do a conditional summation and remove the
WHERE
clause: