select id, name, 'First Category' as category, count(id) as totalCalls
from missed_call
where name = 'whatever1'
group by name, category
UNION
select id, name, 'Second Category' as category, count(id) as totalCalls
from missed_call
where name = 'whatever2'
group by name, category
order by name ASC, totalCalls DESC
前面的查询不会检索totalCalls为 0 的记录。
那么,我该如何获取这些记录并将totalCalls 显示为 0?
更新:我试过改变count(id) as totalCalls
,IFNULL(count(id), 0) as totalCalls
但它不能解决问题。也许,因为 count(id) 实际上不为空,它只是不存在。