MySQL查询语句练习3

没有数据库先执行50q数据库

  1. 查询选修某课程的同学人数多于5人的教师姓名
    Select cno from score group by cno having count(*)>5;
    Select tname from teacher as t inner join course as c on t.tno=c.tno where cno in(Select cno from score group by cno having count(*)>5);
  2. 查询95033班和95031班全体学生的记录
    select * from student where class='95033' or '95031';
  3. 查询出“计算机系“教师所教课程的成绩表
    Select score.*from teacher as inner join course as con t.tno=c.cno inner join score as con c,cno=s.scno
  4. 查询选修编号为“3-105“课程且成绩至少高于选修编号为“3-245”的同学的Cno、Sno和Degree,并按Degree从高到低次序排序。
    Select degree from score where cno=’3-105’
    And degree>all(Select degree from score where cno=’3-245’)
  5. 查询所有姓李的同学的sno,sname,cno,degree
    Select s.sno,sname,cno,degree from student as s inner join score as c no s.sno=c.sno where sname like ‘李%’;
  6. 查询成绩比该课程平均成绩低的同学的成绩表
    Select * from score where degree<(select avg (degree)from score as s where cno=s.cno);
  7. 查询所有任课教师的Tname和Depart
    select tname,depart from teacher where tno in (select tno from course where cno in (select distinct cno from score));
  8. 查询所有未讲课的教师的Tname和Depart
    select tname,depart from teacher where tname not in( select distinct tname from teacher,course,score where teacher.tno=course.tno and course.cno=score.cno);
  9. 查询至少有2名男生的班号
    select class from student where ssex='男' group by class having count(*)>1;
  10. 查询“男”教师及其所上的课程
    select tname,cname from teacher ,course where tsex='男' and teacher.tno=course .tno;
  11. 查询和“李军”同性别并同班的同学Sname
    select sname from student where ssex=(select ssex from student where sname='李军') and sname not in ('李军') and class =(select class from student where sname='李军');

更多查询语句请参考MySQL查询语句集合

原创文章 66 获赞 338 访问量 1万+

猜你喜欢

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