0
我有以下查询:COUNT(*)允许组由空
select count(*) as memo_count, student_id from memo group by student_id
它返回以下结果集:
memo_count student_id
3 0
8 1
不过,我真的很喜欢它返回是这样的:
memo_count student_id
3 0
8 1
0 2
发生什么事情是,集团是过滤出任何计数(*)返回0,这不是我所期望的。任何方式在这个?谢谢。
看看这个:http://stackoverflow.com/questions/1980678/how-to-return-empty-groups-in-sql-group-by-子句 – kol
如果它返回0,那就意味着这个表中不存在'student_id'。你有没有另一张student_id的表格离开这个会返回所有这些? –
它不能计算不存在的东西......你想为每个学生记录一个记录吗? – Ryan