将exists的语句改为in语句

img


利用EXISTS查询没有成绩信息的stuid和stuname,并修改为IN子查询,教教怎么改

select stu_id,stu_name from t_student a
where a.stu_id in (
select distinct b.stu_id from t_score b where b.stu_id=a.stu_id)

改成这样即可:
select stu_id,stu_name
from t_student a
where a.stu_id not in
(select b.stu_id from t_score b );

你这个是 not exists,只能改成not in。绝大多数情况下,不要将not exists改为not in。NOT IN的性能差多了