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、取出选修了全部课程的学生姓名,性别。