问题:查询选修了学分为3或4课程的学生名字
SQl 代码段:
-- 查询选修了学分为3或4课程的学生名字
--自然连接
select distinct sname from 学生,选课,课程
where 学生.sid=选课.sid and 选课.cid=课程.cid
and (课程.credit=3 or 课程.credit=4)
--join on连接
select distinct sname from 学生 join 选课
on 学生.sid=选课.sid join 课程 on
选课.cid=课程.cid and (课程.credit=3 or 课程.credit=4)
--in 连接
select sname from 学生 where sid in(
select sid from 选课 where cid in (
select cid from 课程 where (credit=3 or credit=4)))
--exists 连接
select sname from 学生 where exists(
select * from 选课 where 学生.sid=选课.sid and exists(
select * from 课程 where 选课.cid=课程.cid))
--并集
select sname from 学生,选课,课程
where 学生.sid=选课.sid and 选课.cid=课程.cid and credit=3
union
select sname from 学生,选课,课程
where 学生.sid=选课.sid and 选课.cid=课程.cid and credit=4