Mysql经典面试题

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

    题目如下:

主要考了一些函数的应用,还有经常遇见的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.csdn.net/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表

                              

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值