sql count函数join

时间:2011-12-20 16:01:58

标签: mysql

SELECT c.cname, COUNT(e.ccode) 
FROM class c
INNER JOIN enrolled e ON e.ccode = c.ccode
WHERE room = 'MB100'
AND e.ccode = < 10;

我正在努力找到MB100会议室中学生人数不足10人的课程名称,我哪里错了?

1 个答案:

答案 0 :(得分:2)

您错过了group by c.cname,试试这个:

SELECT c.cname, COUNT(e.ccode) 
FROM class c
INNER JOIN enrolled e ON e.ccode = c.ccode
WHERE room = 'MB100'
Group by c.cname
Having e.ccode =< 10;