我要查询出student_class中,同一个studentId,而它的classId数量大于5的student信息, 有一个student_Info表和class_info表作关系...
数据库是mysql
已经过建表 运行验证成功
select * from
student_info where student_id in (
select student_id from(
select student_id,count(class_id) cnt from
student_class group by student_id ) t where cnt>5
);
谢谢,问题已经解决.用的是:having筛选
select s.STUDENT_ID, s.* from student_Info s where student_Id not in
( select student_Id from student_class
group by student_Id having count(student_Id)>5)
select * from student_info where id in(
(select student_id from
( select student_id ,count( student_id ) as cnt from student_class group by student_id ) as t1
where t1.cnt>5)as t2);
这个简单,看你的信息说明student_id相同的时候,class_id肯定不想同,因为一个班级不可能有两个相同的student_id
所以:select student_id from 结果1 group by student_id having count(student_id) > 5
select student_id from student_class group by student_id having count(distinct class_id)>5
谢谢,问题已经解决.