博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【牛客网】SQL练习
阅读量:4092 次
发布时间:2019-05-25

本文共 963 字,大约阅读时间需要 3 分钟。

 

 

1、考试分数(一)

select job, ROUND(AVG(score)*1.0, 3) `avg` from grade group by job order by `avg` desc;select job, round(avg(score), 3) as avg_score from grade group by job order by avg_score desc;

 

2、考试分数(二)

题目有误,应该是“查找分数大于其所在工作组的平均分的用户”

采用连接的方式:

select grade.id, grade.job, grade.scorefrom grade, (select job, avg(score) as avg_score from grade group by job) as temp where grade.job = temp.job and grade.score > temp.avg_score order by grade.id;select t1.* from grade t1 INNER JOIN (    select job, round(avg(score)*1.0, 3) `avg` from grade group by job) t2on t1.job = t2.job and t1.score > t2.`avg` order by t1.id;

采用子查询的方式:

select x.id, x.job, x.score from grade as x where x.score > (    select avg(y.score) from grade as y where y.job = x.job group by y.job)order by x.id asc;

 

3、考试分数(三)

首先,

select t1.id from grade as t1 join grade as t2 on t1.language_id = t2.language_id and t1.socre <= t2.scoregroup by t1.language_id, t1.id having count(distinct t2.score) < 3;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载地址:http://efnii.baihongyu.com/

你可能感兴趣的文章
凭算法突围,一战赚了 1090 亿,“恐怖” 的张一鸣!
查看>>
200页!分享珍藏很久的Python学习知识手册(附链接)
查看>>
程序员之神
查看>>
大幅提高开发效率的 9 款工具
查看>>
4 岁小女孩给 Linux 内核贡献提交
查看>>
推荐几个私藏很久的技术公众号给大家
查看>>
20 个 2020 年软件开发趋势预测
查看>>
王垠受邀面试阿里 P9,被 P10 面跪后网上怒发文,惨打 325 的 P10 赵海平回应了!...
查看>>
Python 趣味打怪:147 段简单代码助你从入门到大师
查看>>
GitHub 热榜第一:最全中华古诗词数据库,收录30多万诗词
查看>>
“我的名片可以运行 Linux”
查看>>
效果酷炫!开源可视化神器:带你看尽项目的沧桑变化!
查看>>
实测两款 GitHub 开源抢票插件,所有坑我们都帮你踩过了
查看>>
上线 B 站,钢铁侠出镜 AI 科普纪录片!
查看>>
GitHub 标星 2.2w+,一个为云而生的开源数据库,有多强大...
查看>>
手把手教你写出几十种让同事无法维护的代码!
查看>>
按我说的来,让 VS Code 好用 10 倍 | VS Code 新手指南
查看>>
GitHub 标星 1.8w+:What the fuck Python?!
查看>>
2019 最烂密码排行榜大曝光!网友:已中招!
查看>>
牛逼了同学!一位哈工大在读 NLP 博士积累 28W 粉丝
查看>>