sqlServer2005习题与答案

sqlServer2005习题与答案

从学生表Student(Sno,Sname,Ssex,Sage,Sdept)中查询出全体学生的学号与姓名 1. 查询全体学生的详细记录 2. 显示前 5条纪录 3. 显示前 50%条纪录

4. 查询所有年龄在17岁以下的学生姓名及其年龄。 5. 某些学生选修课程后没有参加考试,所以有选课记录,但没有考试成绩。查询缺少成绩的学生的学号和相应的课程号。(成绩为null)

6. 查所有有成绩的学生学号和课程号 7. 查询学生的所有信息,按学号的降序排列 1.select * from student 2.select top 5 * from student

3.select top 50 percent * from student 4.select sname,sage from student where sage<17

5.select sno,cno from sc where score is NULL

6.select sno,cno from sc where score is not NULL

7.select * from student order by sno desc 8 查询选修了课程的学生学号

9. 查全体学生的姓名及其出生年份,显示两列:姓名、出生年份

10. 查询年龄在15~17岁(包括15岁和17岁)之间的学生的姓名、年龄。

11. 查询年龄不在15~17岁之间的学生姓名、系别和年龄。

12. 查询年龄不在15~17岁之间的男生姓名、系别和年龄。

13. 将上题查询的结果插入一个新表中。 8.select distinct sno from sc

9.select sname,2010-sage as 出生年份 from student

10.select sname,sage from student where sage between 15 and 17

11.select sname,sdept,sage from student where sage is not between 15 and 17

12.select sname,sdept,sage from student where ssex='男' and sage is not between 15 and 17 13.select sname,sdept,sage into newtable from student where ssex='男' and sage is not between 15

and 17

1. 查询学生总人数。

2. 查询选修了课程的学生人数。 3. 计算1001号课程的学生平均成绩。 4. 查询选修1号课程的学生最高分数。

5. 求各个课程号及相应的选课人数。(group by) 6. 查询选修了1门以上课程的学生学号。(having) 7. 请说明union的作用。

1.select count(*) from student

2.select count(distinct sno) as 人数 from sc

3.select avg(score) as 平均成绩 from sc where cno =1001

4.select max(score) as 最高分数 from sc where cno =1

5.select cno,count(*) as 选课人数 from sc group by cno

6.select cno, count(*) as 选课人数 from sc group by cno having count(*)>1 1. 查询学生总人数。

2. 查询选修了课程的学生人数。 3. 计算1001号课程的学生平均成绩。

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4