题解 | #统计每个用户的平均刷题数#

统计每个用户的平均刷题数

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

select
    '山东大学' as university,
    d.difficult_level,
    sum(ansNum) / count(d.device_id) as avg_answer_cnt
from
    (
        select
            a.device_id,
            c.difficult_level,
            count(1) as ansNum
        from
            user_profile a
            join question_practice_detail b on a.device_id = b.device_id
            and a.university = '山东大学'
            join question_detail c on b.question_id = c.question_id
        group by
            a.device_id,
            c.difficult_level
    ) d
group by
    d.difficult_level
order by
    avg_answer_cnt desc

暂时这样,优化再说

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务