create table score(
s_id varchar(20),
c_id varchar(20),
s_score int(3),
primary key(s_id,c_id)
);
create table student(
s_id varchar(20),
s_name varchar(20) not null,
primary key(s_id)
);
第一步:查询XXX同学选的所有课
select c_id
from score
where s_id='xxx'
第二步:not in找出选了其他课(xxx同学没选的课)的同学
select s_id
from score stemp
where c_id not in (
select c_id
from score
where s_id='xxx')
第三步:选出不在上一步选出的同学中是同学
select s_id
from score temp
where s_id not in(
select s_id
from score stemp
where c_id not in (
select c_id
from score
where s_id='xxx') )
第四步:对这些同学group by后判断选课数量是否和xxx同学选课数量一样
select s_id,s_name
from student
where s_id in(
select s_id
from score temp
where s_id not in(
select s_id
from score
where c_id not in (
select c_id
from score
where s_id='xxx') )
group by s_id
having count(*)=(select count(*) from score where s_id ='xxx')) and s_id!='xxx';