mysql中出現 Unknown column ‘xxx‘ in ‘having clause‘


mysql中出現 Unknown column ‘xxx‘ in ‘having clause‘

這是因為在使用group by分組時,后面如果需要再加一個having進行判斷,則所判斷的字段需要在select后面出現

如:

select c.studentNo, c.name, count(coursename)
from courses a, scores b, students c
where a.courseNo = b.courseNo
and b.studentNo = c.studentNo
GROUP BY c.studentNo
having count(coursename) = 5

如果不出現,則會報錯

 

 *代碼只是做演示,結果是有問題的


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM