我有类似的查询:
SELECT Zip, COUNT(*) as count
FROM people
WHERE specialty='Driver'
GROUP BY Zip
ORDER BY Zip
它使用0计数过滤掉结果,但即使计数为0,我仍然需要所有分组的拉链。
答案 0 :(得分:4)
您可以使用条件聚合
SELECT Zip, SUM(specialty = 'Driver') as count
FROM people
GROUP BY Zip
ORDER BY Zip