答:在查询结果产生后,提取结果的前若干行数据。
四.上机练习
1.查询学生选课表中的全部数据。
答:select * from SC
2.查询计算机系的学生的姓名、年龄。
答:select sname,sage from student where sdept = '计算机系'
3. 查询成绩在70~80分之间的学生的学号、课程号和成绩。
答:select sno,cno,grade from sc on where grade between 70 and 80
4. 查询计算机系年龄在18~20之间且性别为“男”的学生的姓名、年龄。
答:select sname,sage from student
where sdept = '计算机系' and sage between 18 and 20 and ssex = '男'
5. 查询“C001”号课程的最高分。
答:select max(grade) from sc where cno = 'C001'
6. 查询计算机系学生的最大年龄和最小年龄。
答:select max(sage) as max_age, min(sage) as min_age from student
where sdept = '计算机系'
7. 统计每个系的学生人数。
答:select sdept,count(*) from student group by sdept
8. 统计每门课程的选课人数和考试最高分。
答:select cno, count(*),max(grade) from sc group by cno
9. 统计每个学生的选课门数和考试总成绩,并按选课门数升序显示结果。
答:select sno,count(*), sum(grade) from sc group by sno
order by count(*) asc
10. 查询总成绩超过200分的学生,要求列出学号和总成绩。
答:select sno,sum(grade) from sc group by sno
having sum(grade) > 200
11. 查询选课门数超过2门的学生的学号、平均成绩和选课门数。
答:select sno, avg(grade), count(*) from sc having count(*) > 2
12. 查询选了“C002”课程的学生的姓名和所在系。
答:select sname,sdept from student s join sc on s.sno = sc.sno
where cno = 'C002'