0
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名學生的課程名稱,我該怎麼辦?sql計數函數加入
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名學生的課程名稱,我該怎麼辦?sql計數函數加入
你缺少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;
+1沒有發現這是失蹤了。但是你需要使用'HAVING COUNT(e.ccode)<10; ' – 2011-12-20 16:05:48
@MartinSmith謝謝,其實一旦我看到你的答案,我刪除了我的,+ 77k repatution讓我懷疑我的回答:) – 2011-12-20 16:13:15