Re: [SQL ] 资料选取问题

楼主: rockchangnew (rock)   2016-03-11 23:18:20
※ 引述《littlepigred (小猪鸿)》之铭言:
: 数据库名称:MySQL
: 数据库版本:
: 内容/问题描述:
: 今天去面试遇到一题题目如下:
: name subject score
: ────────────
: aaa math 90
: aaa chem 75
: aaa eng 70
: bbb chem 85
: bbb math 95
: bbb eng 90
: ccc eng 65
: ccc chem 80
: ccc math 75
: 请用SQL语法选出至少2科分数高于85且没有任何一科低于75的人
: 小弟新手 麻烦各为求解QQ
select name from(
select
name
,count(case when score>84 then 1 else null end) as [Over85]
,count(case when score<75 then 1 else null end) as [Below75]
from scoretb group by name) tmp
where [Over85]>=2 and [Below75]=0
楼主: rockchangnew (rock)   2016-03-12 00:42:00
我是用MSSQL,MySQL您要试试看
作者: mrforget (财去人安乐)   2016-03-12 01:31:00
select name from tab where score >= 85 and exists(select name from tab where score <=75)group by name having count(name)>=2;我是用oracle<=75那边有错,应该是<75
作者: littlepigred (小猪鸿)   2016-03-12 23:51:00
我是原po 谢谢各位的解答 考试只说用SQL语法 没特别设限不过我用MYSQL 好像不能用exists执行 我再研究 不过概念我了解了 谢谢各位!

Links booklink

Contact Us: admin [ a t ] ucptt.com