※ 引述《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