一道关于sql的面试题
2016-09-10 10:13
441 查看
存在下面的数据,请通过一条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;
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;
相关文章推荐
- 一道SQL语句面试题,关于group by
- 一道SQL语句面试题,关于group by的
- 一道sql 关于pivot的面试题
- 关于一道sql的面试题 (非常精典) (转)
- 关于一道sql的面试题 (非常精典)
- 一道SQL语句面试题,关于group by
- 关于FOR循环的一道面试题
- 一道sql面试题的多种解答
- 今天没做起的一道SQL面试题
- 开始学习SQL了,请高手回答帮一下小菜鸟,一道面试题
- 关于一道面试题的源代码解答
- 一道SQL题...(关于树型结构的在关系表中的存储及其应用处理)
- 一道关于静态变量的初始化顺序面试题
- 一道sql面试题附答案
- 一道sql面试题附答案
- 关于一道面试题
- 关于一道微软面试题的思考
- 一道关于宏的面试题及解答
- 一道关于字符串操作的面试题
- 一道SQL语句面试题