希望可以帮到你
--查询选修了“计算机体系结构”的学生的基本信息。
select *
from 学生
where 学号 in
(select 学号
from 选课
where 课程号 in
(select 课程号
from 课程
where 课程名称='计算机体系结构'))
--查询年龄比李勇小的学生的学号和成绩。
select 学号,成绩
from 选课
where 学号 in
(select 学号
from 学生
where 年龄<
(select 年龄
from 学生
where 姓名 ='李勇'))
--查询其他系中比系编号为“D1”的学生中年龄最小者要最大的学生的信息。
select *
from 学生
where 系编号<>'D1'and 年龄>
(select min (年龄)
from 学生
where 系编号='D1')
--查询其他系中比系编号为“D3”的学生年龄都大的学生的姓名。
select 姓名
from 学生
where 系编号<>'D3'and 年龄>all
(select 年龄
from 学生
where 系编号='D3')
--查询“C1”课程的成绩高于70分的学生姓名。
select 姓名
from 学生
where 学号 in
(select 学号
from 选课
where 课程号 ='C1'and 成绩>70)
--查询“C1”课程的成绩不高于70分的学生姓名。
select 姓名
from 学生
where 学号 in
(select 学号
from 选课
where 课程号 ='C1'and 成绩<=70)
--查询选修了所有课程的学生姓名。
select 姓名
from 学生
where not exists
(select *
from 课程
where not exists
(select *
from 选课
where 学生.学号=选课.学号 and 课程.课程号=选课.课程号))
--查询学校开设的课程总数。
select count(*)
from 课程
--查询选修两门以上课程的学生姓名。
select 姓名
from 学生
where 学号 in
(select 学号
from 选课 group by 学号 having count(*)>=2)
--查询开设的课程和选修该课程的学生的总成绩、平均成绩、最高成绩和最低成绩。
select 课程号,sum(成绩),avg(成绩),max(成绩),min(成绩)
from 选课 group by 课程号
--查询系编号为“D2”或选修课程的最低成绩大于等于60分的学生信息。
select *
from 学生
where 系编号='D2'
union
select *
from 学生
where 学号 in
(select 学号
from 选课 group by 学号 having min(成绩)>=60)
温馨提示:答案为网友推荐,仅供参考