MySQL查询语句练习1

  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=85 or degree=86 or degree=88;
  6. 查询Student表中“95031”班或性别为“女”的同学记录
    select * from student where class='95031' and ssex='女';
  7. 以Class降序查询Student表的所有记录
    select * from student order by class desc;
  8. 以Cno升序、Degree降序查询Score表的所有记录
    select * from score order by degree desc , cno;
  9. 查询“95031”班的学生人数
    select count(*) as '人数' from student where class='95031';
  10. 查询Score表中的最高分的学生学号和课程号
    select * from score order by degree desc limit 1;
  11. 查询‘3-105’号课程的平均分
    select avg(degree) from score where CNO='3-105';
  12. 查询Score表中至少有5名学生选修的并以3开头的课程的平均分数
    select cno,avg(degree) from score where cno like '3%' group by cno having count(sno)>5;
  13. 查询最低分大于70,最高分小于90的Sno列
    select sno from score group by sno having min(degree)>70 and max(degree)<90;
    在这里插入图片描述
原创文章 53 获赞 323 访问量 1万+

猜你喜欢

转载自blog.csdn.net/Long_UP/article/details/106123784