首页 > 数据库技术 > 详细

mysql练习题

时间:2021-06-06 21:29:36      阅读:30      评论:0      收藏:0      [点我收藏+]

基础题:

-- 1、 查询Student表中的所有记录的Sname、Ssex和Class列。

select sname,ssex,class from student;

 

-- 2、 查询教师所有的单位即不重复的Depart列。

select distinct depart from teacher;

 

-- 3、 查询Student表的所有记录。

select * from student;

-- 4、 查询Score表中成绩在60到80之间的所有记录。

select * from score where degree between 60 and 80;

-- 5、 查询Score表中成绩为85,86或88的记录。

select * from score where degree in(85,86,88);

 

-- 6、 查询Student表中"95031"班或性别为"女"的同学记录。

select * from student where class="95031";

-- 7、 以Class降序查询Student表的所有记录。

select * from student order by class desc;

 

-- 8、 以Cno升序、Degree降序查询Score表的所有记录。

select * from score order by cno and degree desc;

 

-- 9、 查询"95031"班的学生人数。

select * from student where class= 95031;

-- 10、 查询Score表中的最高分的学生学号和课程号。(子查询或者排序)

select sno,cno from score having max(degree);

10.1 查询Score表中除了每门课程最高分的学生学号和课程号。(子查询或者排序)

select sno,cno from score where degree != (select max(degree) from score);

拔高题:

-- 11、查询每门课的平均成绩。

select avg(degree) from score group by degree;

 

-- 12、查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。

select avg(degree) from score group by sno=3 and degree;

 

-- 13、查询分数大于70,小于90的Sno列。

select sno from score where degree between 70 and 90;

-- 14、查询所有学生的Sname、Cno和Degree列。

select student.sname,score.cno,score.degree from student student left join score score on student.sname = score.sno;

-- 15、查询所有学生的Sno、Cname和Degree列。

select score.cno,course.cname,score.degree from score score left join course course on score.cno=course.cno;

-- 16、查询所有学生的Sname、Cname和Degree列。

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"班学生的平均分。

select avg(degree) from score where sno in (select sno from student where class = 95033);

 

mysql练习题

原文:https://www.cnblogs.com/yuguog/p/14856202.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!