题解 | 统计复旦用户8月练题情况

select 
distinct device_id, university, SUM(CASE WHEN result=0 THEN 0 ELSE 1 END) over(partition by device_id) as question_cnt, SUM(CASE WHEN result=2 THEN 1 ELSE 0 END) over(partition by device_id) as right_question_cnt
from
(
    select  device_id, 
            university, 
            CASE
                WHEN state_question_cnt = "right" THEN 2
                WHEN state_question_cnt = "wrong" THEN 1
                WHEN state_question_cnt = "0" THEN 0
                ELSE 0 
            END AS result
    from
    (
        select   device_id, 
                university,
                ifnull(result, 0) as state_question_cnt

        from 
        (
            select *
            from 
            (
                select up.device_id, university, result, Year(date) as Y, Month(date) as M
                from 
                user_profile as up left join
                question_practice_detail as qpd
                on up.device_id=qpd.device_id
                where up.university="复旦大学"
            ) as t
            where 
            (case when Y=2021 and M=8 then 1 else 0 end) + 
            (case when Y is NULL then 1 else 0 end)
        ) as t1
    ) as t2
) as t3



全部评论

相关推荐

06-26 15:35
武汉大学 运营
点赞 评论 收藏
分享
06-19 19:06
门头沟学院 Java
码农索隆:别去东软,真学不到东西,真事
点赞 评论 收藏
分享
争当牛马还争不上
码农索隆:1.把简历改哈 2.猛投,狠投 3.把基础打牢 这样你在有机会的时候,才能抓住
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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