mysql 分组统计总数 没有的默认为0

2024-11-15 21:49:50
推荐回答(1个)
回答1:

SELECT
a.room_id,
IFNULL(t1.count1, 0)
FROM
a
LEFT JOIN
(SELECT
room_name,
COUNT(*) AS count1
FROM
b
GROUP BY room_name) t1
ON a.`room_id` = t1.room_name
看看是你要的效果吗