当前位置:首页 > 实验二SQL语言的基本使用
实验二SQL语言的基本使用,数据查询
一.实验目的:熟悉SQL语言的基本使用,数据查询、表与表之间的操作,聚全函数的
使用,以及分组多表查询等。学会处理复杂问题的查询方法。
二.实验内容(请先扩充原数据表中的记录数):
1. 查询所有学生的姓名、学号和所在系
2. 请查询出生年在1981年后的学生学号和姓名 3. 查询信息系的全体男生的姓名与学号
4. 查询所有年龄在20岁以下的学生姓名及年龄,假设当前年号为2000年 5. 查询所有选修过课的学生的学号(思考如果去掉重复行该怎样进行) 6. 查询所有姓刘的学生的姓名,学号,性别
7. 查询选修课成绩情况,要求按课程号升序排列,对同一课程号按成绩降序排列 8. 查询学生总人数
9. 查询选修了课程的学生人数 select count(distinct sno) from sc 10. 计算1号课程的学生平均成绩 11. 计算选修了1号课程的学生总成绩 12. 查询99001班的学生人数
13. 查询99001班的学生的平均成绩;
14. 查询各个课程号与相应的选课人数select cno, count(sno) from sc group by cno; 15. 查询每个学生的学号和相应的平均成绩select sno,avg(grade) from sc group by sno; 16. 查询平均成绩大于等于90分的学生学号select sno from sc group by sno having
avg(grade)>90
17. 查询信息系学生与性别为女性的学生号及姓名select sno,sname from student where
sdept=’信息系’or sex=’ 女’
18. 查询即是信息系的学生又是女学生的学生号及姓名。Select sno,sname from student
where sdept=’信息系’and sex=’女’;
19. 查询信息系平均成绩大于90分的学生学号select sno from student where sno in
(select sno from sc group by sno having avg(grade)>'80')and sdept='信息系';或者是:select sc.sno from student,sc where student.sno=sc.sno and sdept=’信息系’group by sc.sno having avg(grade)>90;
20. 查询与“刘晨”在同一个系学习的学生selelct *from student where sdept=(select
sdept from student where sname=’刘晨’);
21. 查询选修了课程名为’信息系统’的学生学号和姓名select student.sno,sname from
student,sc,course where student.sno=sc.sno and sc.cno=course.cno and cname='信息系统';
22. 找出有选修课程中成绩最高的同学的姓名及成绩) select sname,grade from
student,sc where student.sno=sc.sno and grade=(select max(grade) from sc)
23. 查询信息系选修了2门以上课程的学生的学号select student.sno from student,sc
where student.sno=sc.sno and sdept=’信息系’group by student.sno having count(*)>2;
24. 查询其他系中比信息系任一学生年龄小的学生名单select sname from student where
year(csrq)>any(select year(csrq) from student where sdept='信息系');
25. 查询其他系中比信息系所有学生年龄都小的学生名单
26. 查询所有选修了1号课程的学生姓名select sname from student,sc where student.sno=sc.sno and cno='1' ; select *from student;
select *from sc where grade between 60 and 80;
共分享92篇相关文档