这是一次面试的时候遇到的题目,平时用起来感觉没什么。但是手写就凉凉了,归根到底还是基础不行呀,所以就写了这篇博客巩固一下。
题目如下:

主要考了一些函数的应用,还有经常遇见的group by,having。
#求出该班级语文的平均分
-- select AVG(score) from score where subject='语文'
#统计该班男生人数
-- select count(sex) from student where sex='男'
#语数英3科平均分在90分以上的同学
-- select name from student where name_id in
-- (select name_id from score GROUP BY name_id HAVING sum(score)>270)
#(group by 使用时如果是有条件的,就得用having, 不得使用where)
这里我用关联查询,查出来的是名字
注:group by 和where的具体使用可以看看我的另外一篇博客
https://blog.youkuaiyun.com/Certain_/article/details/89787255
#语数英3科中有2科大于90分的同学
select name_id from score where score>90 group by name_id having count(name_id)>=2
全部代码在这里:
https://github.com/Certain97/Mysql-/tree/master
score表 student表

博主因面试时手写函数应用等题目失利,写博客巩固基础。内容包含求班级语文平均分、统计男生人数、筛选语数英3科平均分超90分及有2科大于90分的同学等SQL查询,还提及group by和having的使用,给出相关代码链接。
3万+

被折叠的 条评论
为什么被折叠?



