白青林

博客园 首页 新随笔 联系 订阅 管理

基础题:
-- 1、 查询Student表中的所有记录的Sname、Ssex和Class列。1
select sname,ssex,class from student;
-- 2、 查询教师所有的单位即不重复的Depart列。1
select distinct depart from teacher;
-- 3、 查询Student表的所有记录。1
select * from student;
-- 4、 查询Score表中成绩在60到80之间的所有记录。1
select * from score where degree between 60 and 80;
-- 5、 查询Score表中成绩为85,86或88的记录。1
select * from score where degree in(85,86,88);
-- 6、 查询Student表中"95031"班或性别为"女"的同学记录。1
select * from student where class="95031";
-- 7、 以Class降序查询Student表的所有记录。1
select * from student order by class desc;
-- 8、 以Cno升序、Degree降序查询Score表的所有记录。1
select * from score order by cno and degree desc;
-- 9、 查询"95031"班的学生人数。1
select * from student where class= 95031;
-- 10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)1
select sno,cno from score having max(degree);
-- 10.1 查询Score表中除了每门课程最高分的学生学号和课程号。(子查询或者排序) 1
select sno,cno from score where degree != (select max(degree) from score);

拔高题:
-- 11、查询每门课的平均成绩。1
select avg(degree) from score group by degree;
-- 12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。1
select avg(degree) from score group by sno=3 and degree;
-- 13、查询分数大于70,小于90的Sno列。1
select sno from score where degree between 70 and 90;
-- 14、查询所有学生的Sname、Cno和Degree列。 1
select student.sname,score.cno,score.degree from student student left join score score on student.sname = score.sno;
-- 15、查询所有学生的Sno、Cname和Degree列。1
select score.cno,course.cname,score.degree from score score left join course course on score.cno=course.cno;
-- 16、查询所有学生的Sname、Cname和Degree列。1
select student.sname,course.cname,score.degree from student student left join score score on student.sname = score.sno left join course course on score.cno = course.cno;
-- 17、查询"95033"班学生的平均分。1
select avg(degree) from score where sno in (select sno from student where class = 95033);
```

posted on 2021-06-06 18:31  白青林  阅读(33)  评论(0编辑  收藏  举报