早教吧 育儿知识 作业答案 考试题库 百科 知识分享

这个sql查询语句看不懂,是pl-sql吗?selectteacherid,subjectname,sum(及格人数)count,round(sum(及格人数)/sum(人数),2)*100||'%'及格率from(selectteacherid,subjectname,casewhenscores>=60then1else0end及格人数,1人数f

题目详情
这个sql查询语句看不懂,是pl-sql吗?
select teacherid,subjectname,sum(及格人数) count,round(sum(及格人数)/sum(人数),2)*100||'%' 及格率
from(select teacherid,subjectname,case when scores>=60 then 1 else 0 end 及格人数,1 人数 from rock);
这个查询语句看不懂,是pl-sql吗?
▼优质解答
答案和解析
里面的几个聚合函数,不都是在sql或pl-sql中的语法么;
使用聚合函数,必须要结合Group by 来进行分组 (除了聚合函数以外的字段);
round(sum(及格人数)/sum(人数),2)*100:四舍五入保留两位小数后,在乘以100;
case when scores>=60 then 1 else 0 end 及格人数:相当于if---else 条件判断,如果分数大于60,结果为1,否则 为0,“及格人数”是该字段的别名
.