1)
select 课程号, 课程名称
from 课程表
where 教师姓名='李老师'
2)
select 学号, 姓名 from 学生表
where (性别='女') and (年龄>23)
3)
select 课程名称 from 课程表
where 课程号 in
(select 选课表.课程号 from 选课表,学生表
where (选课表.学号=学生表.学号) and (学生表.姓名='李小波'))
4)
select 姓名, 所在系 from 学生表 where 学号 in
(select distinct 学号from 选课表 where 成绩 >= 80)
5)没有选修“操作系统”课的学生姓名。
select distinct 学生表.学号, 姓名
from 学生表, 选课表, 课程表
where (选课表.学号=学生表.学号) and (选课表.课程号=课程表.课程号)
and (课程名称 <>'操作系统')
6)英语成绩比数学成绩好的学生。
create function 课程成绩(@课程名 nchar(255), @学号 char(6))
returns numeric as
begin
declare @i numeric
select @i=成绩 from [选课表], [课程表]
where (学号 = @学号) and ([选课表].[课程号] =[课程表].[课程号]) and ([课程名称] = @课程名)
return @i
end
select 学号, 姓名,
英语成绩= dbo.课程成绩('英语',学号), 数学成绩= dbo.课程成绩('数学',学号)
from 学生信息表
where dbo.课程成绩('英语',学号)>dbo.课程成绩('数学',学号)
7)至少选修两门以上课程的学生姓名、性别。
select [姓名], [性别] from [学生表]
where [学号] in
(SELECT [学号] FROM [选课表]
group by [学号] having count([学号])>1)
8)选修了李老师所讲课程的学生人数。
select count(学号)
from 选课表, 课程表
where (选课表.课程号=课程表.课程号) and (教师姓名='李老师')
9)没有选修李老师所讲课程的学生,
select distinct 学生表.学号, 学生表.姓名
from 学生表, 选课表, 课程表
where (选课表.学号=学生表.学号) and (选课表.课程号=课程表.课程号)
and (教师姓名<>'李老师')
10)“操作系统”课程得最高分的学生姓名、性别、所在系。
select top 1 学生表.学号, 姓名, 所在系
from 学生表, 选课表, 课程表
where (选课表.学号=学生表.学号) and (选课表.课程号=课程表.课程号)
and (课程名称 = '操作系统')
order by 成绩 desc