题解 | 各用户等级的不同得分表现占比

各用户等级的不同得分表现占比

https://www.nowcoder.com/practice/ebff819fd38c46db8a42dfe43ca7b33a

with
    score as (
        select
            er.uid,
            exam_id,
            score,
            level,
            case
                when score >= 90 then '优'
                when score >= 75 then '良'
                when score >= 60 then '中'
                else '差'
            end score_grade,
            count(
                case
                    when score >= 90 then '优'
                    when score >= 75 then '良'
                    when score >= 60 then '中'
                    else '差'
                end
            ) over (
                partition by
                    level
            ) 计数
        from
            test.user_info ui
            join test.exam_record er on ui.uid = er.uid
        where
            score is not null
    )
select
    level,
    score_grade,
    round(count(uid) / 计数, 3) ratio
from
    score
group by
    level,
    score_grade,
    计数
order by
    level desc,
    ratio desc

全部评论

相关推荐

积极的小学生不要香菜:你才沟通多少,没500不要说难
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务