问题描述
您好,我在 Redshift 中有一个表格,其中有几个学生的成绩单记录,如下所示。我想算出每所大学(uni1、uni2 和 uni3)的批准率是多少。当学生的成绩大于 D+ 或大于 50 时,即被批准:
我现在正在尝试使用以下查询按大学计算批准率:
select 'uni1' as uni,count (case when (grade > 50 and grade not in ('D+','D','D-','F')) then 1 end) as passed,count(*) as total,(passed / total)*100 as ratio
from analytics.students_fact
where uni= 'uni1' and grade <> 'Unknown';
union
select 'uni2' as uni,(passed / total)*100 as ratio
from analytics.students_fact
where uni= 'uni2' and grade <> 'Unknown';
union
select 'uni3' as uni,(passed / total)*100 as ratio
from analytics.students_fact
where uni= 'uni3' and grade <> 'Unknown';
上述查询的问题在于“等级”字段将数字作为整数,将数字作为字符串以及字母等级(A+、A、B+ 等)。我应该如何解决这个问题并确保我涵盖所有学生?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)