MySQL综合练习查询1

  1. 查询所有学生的学号、选课数、总成绩
    Select sno,count(cno),sum(degree)from score group by sno;
  2. 查询姓“张”的老师的个数
    select count(*) from Teacher where Tname like '张%';
  3. 查询平均成绩大于60分的学生的学号和平均成绩
    Select sno,avg(degree)from score group by sno having avg(degree)>60;
  4. 查询没学过“张旭”老师课的学生的学号、姓名
    Select cno from course inner join teacher on course.tno=teacher.tno where tname=’张旭’;
    Select sno from score where cno in (select cno from course inner join teacher on course.tno=teacher.tno where tname =’张旭’);
    Select sno,sname from student where sno not in (select sno from score where cno in (select sno from course inner join teacher on course.tno where tname =’张旭’));
  5. 查询课程编号为“3-105”的总成绩
    Select sun(degree) from score where cno=’3-105’;
  6. 查询所有课程成绩小于60分的学生的学号、姓名
    select s.sno,s.sname from student s join sc c on s.sno=c.sno where c.sno not in (select distinct sno from sc where score>60);
  7. 查询没有学全所有课的学生的学号、姓名
    Select sno,count(cno) from score group by sno having count(cno) < (select count (cno)from course;
原创文章 57 获赞 323 访问量 1万+

猜你喜欢

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