结果肯定是错误的,你可以试一下:sc表内容(学号,课程号,成绩): s1,1,90 s1,2,90 s1,3,90 s2,1,90 s3,1,80 s3,2,80 正确的结果应该是s1. 你试一下下面的结果: select distinct student.sno,student.sname from student,sc where student.sno=sc.sno and sc.scno in (select scno from sc where sno='s3')结果是: s1 aaaa s2 bbbb s3 cccc 因为在s3中有一门课程1是符合条件的。
select a.学号,b.姓名 from sc a,student b where a.学号 = b.学号 and not exists(select 课程号 from sc where 学号 = 's3' minus select 课程号 from sc where 学号 = a.学号 ) group by a.学号
sorry! test it:select a.学号,min(b.姓名) from sc a,student b where a.学号 = b.学号 and not exists(select 课程号 from sc where 学号 = 's3' minus select 课程号 from sc where 学号 = a.学号 ) group by a.学号
select a.学号,a.姓名 from student a where a.学号 = b.学号 and not exists(select 课程号 from sc where 学号 = 's3' minus select 课程号 from sc where 学号 = a.学号 ) and a.学号 <> 's3'
select a.学号,a.姓名 from student a where not exists(select 课程号 from sc where 学号 = 's3' minus select 课程号 from sc where 学号 = a.学号 ) and a.学号 <> 's3'
关键在于:全部课程。
例如:
学生s1,选修课程1,2,3
学生s2,选修课成1
学生s3,选修课程1,2则我应该选出的是学生s1
from student,sc
where student.学号=sc.学号
and count(sc.课程号)>=(select count(课程号)
from sc
where 学号='s3');
如果学生s1,选修1,2,3
学生S2,选修1,4,5,8
学生S3,选修1,2
则你的结果就是s1,s2了,但是正确的应该是s1
如果加上个distinct就更完美了。
子查询选出的就是s3的全部课程啊,而且你只求学号和姓名,联系上
sc表的存储方式,zhenyukeji(何处是我家) 得出的结果应该是正确
结果,希望你自行测试一下。
s1,1,90
s1,2,90
s1,3,90
s2,1,90
s3,1,80
s3,2,80
正确的结果应该是s1.
你试一下下面的结果:
select distinct student.sno,student.sname from student,sc
where student.sno=sc.sno
and sc.scno in (select scno from sc where sno='s3')结果是:
s1 aaaa
s2 bbbb
s3 cccc
因为在s3中有一门课程1是符合条件的。
from sc a,student b
where a.学号 = b.学号
and not exists(select 课程号 from sc where 学号 = 's3'
minus
select 课程号 from sc where 学号 = a.学号
)
group by a.学号
test it:select a.学号,min(b.姓名)
from sc a,student b
where a.学号 = b.学号
and not exists(select 课程号 from sc where 学号 = 's3'
minus
select 课程号 from sc where 学号 = a.学号
)
group by a.学号
from student a
where a.学号 = b.学号
and not exists(select 课程号 from sc where 学号 = 's3'
minus
select 课程号 from sc where 学号 = a.学号
)
and a.学号 <> 's3'
from student a
where not exists(select 课程号 from sc where 学号 = 's3'
minus
select 课程号 from sc where 学号 = a.学号
)
and a.学号 <> 's3'