您好,欢迎来到叨叨游戏网。
搜索
您的当前位置:首页查询和XXX同学学习的课程完全相同的其他同学学号和姓名

查询和XXX同学学习的课程完全相同的其他同学学号和姓名

来源:叨叨游戏网
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';

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- gamedaodao.net 版权所有 湘ICP备2024080961号-6

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务