(1)查询计算机系年龄小于等于20岁的学生姓名:
select SN from S where AGE<=20 and dept='计算机系'
(2)查询修读课程号为c1的所有学生的姓名:
select SN from S where S# in(select distinct S# from SC where C#=(
select C# from C where CN='c1'))
(3)查询修读课程名为JAVA的所有学生姓名
select SN from S where S# in(select distinct S# from SC where C#=(
select C# from C where CN='JAVA'))
(4)查询所有成绩都不及格的学生姓名
select SN from S where S# in
(
--以学号分组得到最小分数 having 过滤不及格的分数得到的学生ID!
select S# from(
--查询所有学生所有课程的分数
select *,isnull(GRADE,0) from (select S#,C# from S,C)temp left join SC on temp.S#=SC.S# and temp.C#=SC.C#) temp
group by S# having min(GRADE)<60
)
案例如上:
希望能帮到你!