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

如果不出现,则会报错

 

 *代码只是做演示,结果是有问题的

posted @ 2021-04-13 12:34  莫困顿  阅读(10482)  评论(0编辑  收藏  举报