MySQL经典练习题(四)

时间:2021-06-29 15:26:20   收藏:0   阅读:0

1、查询成绩比该课程平均成绩低的同学的成绩表

SELECT *

FROM score AS a

WHERE degree < (SELECT AVG(degree) FROM score AS b WHERE a.cno = b.cno)

技术图片

2、查询所有任课教师的Tname和Depart.

select tname,depart

from teacher t,course c

where t.tno = c.tno

技术图片

3、查询所有未讲课的教师的Tname和Depart

select Tname,Depart

from Teacher

where Tname not in (select Tname from Teacher,Course,Score where Teacher.Tno=Course.Tno and Course.Cno=Score.Cno)

技术图片

4、查询至少有2名男生的班号。

select class

from student

where ssex =‘男‘

group by class

having count(sno)>=2

技术图片

5、查询Student表中不姓“王”的同学记录。

select *

from student

where sname not like ‘王%‘

技术图片

6、查询Student表中最大和最小的Sbirthday日期值。

select MAX(Sbirthday) as min_sbirthday,MIN(Sbirthday) as max_sbirthday

from student

技术图片

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!