一道关于sql的面试题

存在下面的数据,请通过一条sql语句将其中每门课的分数都大于80的筛选出来
names  classes  score
A        语文    83
A        数学    87
B        语文    83
B        数学    67
C        语文    83
C        数学    87
C        英语    77




insert into  ttt values('A','语文',83);
insert into  ttt values('A','数学',87);
insert into  ttt values('B','语文',83);
insert into  ttt values('B','数学',67);
insert into  ttt values('C','语文',83);
insert into  ttt values('C','数学',83);
insert into  ttt values('C','英语',77);




1.原理: 将大于80的个数找出来 与总的比较。 然后筛选出相等的即可
select a.name1 from 
(select count(t1.classes) num1, t1.names name1 from ttt t1 where t1.score > 80 group by t1.names) a,
(select count(t2.classes) num2, t2.names name2 from ttt t2  group by t2.names) b
 where a.num1 = b.num2 and a.name1 = b.name2;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值