菜鸟求助SQL面试题两道!

qdwllsq 2016-10-11 04:56:13

菜鸟求助,两道SQL面试题。不知道如何解决?



望大神解答!非常感谢!
...全文
558 11 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
FBI_xuye_007 2016-10-12
  • 打赏
  • 举报
回复
select name '姓名',SUM(distinct score) '总分' from Table_1 group by name having SUM(distinct score)>100 select (case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文, (case when 数学>=80 then '优秀' when 数学>=60 then '及格' else '不及格') as 数学, (case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table
qdwllsq 2016-10-12
  • 打赏
  • 举报
回复
引用 3 楼 u014038116 的回复:
select * from (select * from table group by name,grade) a group by name having sum(score)>100;


select
(case when 语文>=80 then '优秀'
when 语文>=60 then '及格'
else '不及格') as 语文,
(case when 数学>=80 then '优秀'
when 数学>=60 then '及格'
else '不及格') as 数学,
(case when 英语>=80 then '优秀'
when 英语>=60 then '及格'
else '不及格') as 英语,
from table


感谢提供指导!可否再指点一二!
结果如下图,少了一条 wang的信息。而且为何分数显示的是某一条记录,并非总和。


第二题SQL执行报错。
表名是r。虽然有乱码,但不影响执行。如果命令正确也可以正确搜索记录并显示。
请大神再给看看,这是神马错误。。改了半天一直是报错,好像就不让我用 case when似的。。。.
xiaovhao 2016-10-12
  • 打赏
  • 举报
回复
select * from (select * from table group by name,grade) a group by name having sum(score)>100; select (case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文, (case when 数学>=80 then '优秀' when 数学>=60 then '及格' else '不及格') as 数学, (case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table
qdwllsq 2016-10-12
  • 打赏
  • 举报
回复
引用 1 楼 ctang2 的回复:
select * from table GROUP BY name,grade HAVING SUM(score) > 100;

非常感谢,但是结果并不理想。只有zhang一个了。
qq_17412031 2016-10-12
  • 打赏
  • 举报
回复
SELECT a.name,SUM(a.score) FROM (SELECT DISTINCT NAME,gade,score FROM chengji) a GROUP BY a.name HAVING SUM(score)>100;
qq_17412031 2016-10-12
  • 打赏
  • 举报
回复
SELECT a.name,SUM(a.score) FROM (SELECT DISTINCT NAME,gade,score FROM chengji) a GROUP BY a.name;
xiaovhao 2016-10-12
  • 打赏
  • 举报
回复
引用 7 楼 qdwllsq 的回复:
可以了 感谢大家。 第一题 select * from (select * from table group by name,grade) a group by name having sum(score)>100; 或者 select name '姓名',SUM(distinct score) '总分' from Table_1 group by name having SUM(distinct score)>100 都可以。谢谢两位! 第二题 select (case when chinese >=80 then '优秀' when chinese>=60 then '及格' else '不及格' end) 语文, (case when math >=80 then '优秀' when math >=60 then '及格' else '不及格' end) 数学, (case when english >= 80 then '优秀' when english >=60 then '及格' else '不及格' end) 英语 from table; 原来是少了一个end。已经可以显示结果了,不过还有一个小问题不能按题目上的要求显示,去除那些空值。
select name '姓名',SUM(distinct score) '总分' from Table_1 group by name having SUM(distinct score)>100我怎么感觉这个是不可以的,他还是没有起到去重的效果,如果同个人,不同课程,同样分数,这个语句结果就不对了
拘谨的小人 2016-10-12
  • 打赏
  • 举报
回复
引用 1 楼 ctang2 的回复:
select * from table GROUP BY name,grade HAVING SUM(score) > 100;
总成绩 应该去点 grade吧
qdwllsq 2016-10-12
  • 打赏
  • 举报
回复
可以了 感谢大家。 第一题 select * from (select * from table group by name,grade) a group by name having sum(score)>100; 或者 select name '姓名',SUM(distinct score) '总分' from Table_1 group by name having SUM(distinct score)>100 都可以。谢谢两位! 第二题 select (case when chinese >=80 then '优秀' when chinese>=60 then '及格' else '不及格' end) 语文, (case when math >=80 then '优秀' when math >=60 then '及格' else '不及格' end) 数学, (case when english >= 80 then '优秀' when english >=60 then '及格' else '不及格' end) 英语 from table; 原来是少了一个end。已经可以显示结果了,不过还有一个小问题不能按题目上的要求显示,去除那些空值。
qdwllsq 2016-10-12
  • 打赏
  • 举报
回复
引用 3 楼 u014038116 的回复:
select * from (select * from table group by name,grade) a group by name having sum(score)>100; select (case when 语文>=80 then '优秀' when 语文>=60 then '及格' else '不及格') as 语文, (case when 数学>=80 then '优秀' when 数学>=60 then '及格' else '不及格') as 数学, (case when 英语>=80 then '优秀' when 英语>=60 then '及格' else '不及格') as 英语, from table
是我疏忽,wang的总分不够100抱歉。
ctang2 2016-10-11
  • 打赏
  • 举报
回复
select * from table GROUP BY name,grade HAVING SUM(score) > 100;

51,396

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧