1、查询所有数学系学生的信息。
--select * from s where 系='数学系'
2、查询李老师所教的课程号、课程名
--select 课程号,课程名from c where 教师like '李%'
3、查询年龄大于20岁的女同学的学号和姓名。
--select 学号,姓名from s where year(getdate())-year(出生日期)+1>20 and 性别='女'
4、查询学号为‘H0301’所选修的全部课程成绩。
--select 成绩from sc where 学号= 'H0301'
5、查询平均成绩都在80分以上的学生学号及平均成绩。
--select 学号,AVG(成绩) from sc group by 学号having AVG(成绩)>=80
6、查询至少有6人选修的课程号。
--select 课程号from sc group by 课程号having count(*)>6
7、查询C02号课程得最高分的学生的学号
--select 学号from sc where 课程号='c02' and 成绩=(select max(成绩) from sc where 课程号='c02')
8、查询学号为’J0101’的学生选修的课程号和课程名
--select 课程号,课程名from c,sc where 学号='j0101' and c.课程号=sc.课程号
9、‘李小波’所选修的全部课程名称。
--Select c.课程名from s,c,sc where s.学号=sc.学号and c.课程号=sc.课程号and 姓名='李小波'
10、所有成绩都在70分以上的学生姓名及所在系。
--select 姓名,系from s,sc where s.学号=sc.学号group by 学号having min(成绩)>=70
11、英语成绩比数学成绩好的学生
--select sc2.学号from c c1,c c2,sc sc1,sc sc2 where c1.课程名='英语'
--and c2.课程名='数学' and sc1.成绩>sc2.成绩and sc1.学号=sc2.学号
--and c1.课程号=sc1.课程号and c2.课程号=sc2.课程号
12、至少选修了两门课及以上的学生的姓名和性别
select 姓名,性别from s,sc
--where s.学号=sc.学号group by 学号having count(*)>=2
13、选修了李老师所讲课程的学生人数
--select count(*) from C,sc where 教师like '李%' and c.课程号=sc.课程号group by sc.课程号
14、‘操作系统’课程得最高分的学生的姓名、性别、所在系
--select 姓名,性别,系from s,sc
--where s.学号=sc.学号and 成绩=
--(select max(成绩) from c,sc where sc.课程号=c.课程号and 课程名='操作系统')
15、显示所有课程的选修情况。
--select * from c left join sc on c.课程号=sc.课程号
16、取出没有选修‘操作系统’课程的学生姓名和年龄
select 姓名,(year(getdate())-year(出生日期))as 年龄from s,c,sc where sc.学号=s.学号and
c.课程号=sc.课程号and 课程号not in (select 课程号from c where 课程名='操作系统')
17、没有选修李老师所讲课程的学生
--select 学号from sc where 课程号not in (select 课程号from c where 教师like '李%')
18、取出选修了全部课程的学生姓名,性别。