gpt4 book ai didi

mysql - 如何在我的查询中显示零计数?

转载 作者:行者123 更新时间:2023-12-01 00:08:47 24 4
gpt4 key购买 nike

如何让我的查询也输出 0 计数结果?我已经看到很多关于如何执行此操作的示例,但是当我尝试将这些示例应用于我自己的查询时,我遇到了困难。

SELECT device.type, COUNT(device.type) AS count 
FROM devices
WHERE device.type IN ('type1', 'type2')

例如 type2 在设备表中不存在。

非常感谢您的帮助,如果您认为这个问题最好不要在这里分享,我们深表歉意。

最佳答案

SELECT t.type, COUNT(device.type) AS count 
FROM
(select 'type1' as type
union all
select 'type2' as type) t LEFT JOIN
devices on devices.type=t.type
GROUP BY t.type

关于mysql - 如何在我的查询中显示零计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48521375/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com