SQL COUNT为零

时间:2015-09-09 02:28:29

标签: sql sqlite

SELECT COUNT(*) totalStudent,
c.* 
FROM classroom c 
INNER JOIN student s
ON c.classID = s.classID 
GROUP BY c.classID 

如何在totalStudent中获得零?如果学生在教室里空了。

1 个答案:

答案 0 :(得分:1)

我将你的问题解释为:“有些班级没有学生。我如何包括这些?”如果这是正确的,则密钥为left join

SELECT c.classId, COUNT(s.classId)
FROM classroom c LEFT JOIN
     student s
     ON c.classid = s.classid
GROUP BY c.classId;