问题遇到的现象和发生背景
列了个视图,需要查询aid和为2(选了两门课程)。但是出来的只有列名没有数据(count(aid)=2),把2改为0数据又出来了,但不是我想要的。所以想问问大家我代码哪里打错了啊。
问题相关代码,请勿粘贴截图
create view cgs
as
select a.name as aname,a.class,c.grade,b.name as bname,a.studentid as aid,c.courseid as cid
from student as a join grade as c
on a.studentid=c.studentid
join course as b
on b.courseid=c.courseid
select aname,class,grade,bname,aid from cgs
group by aname,class,grade,bname,aid having count(aid)>2