题解 | #每个6/7级用户活跃情况#

每个6/7级用户活跃情况

http://www.nowcoder.com/practice/a32c7c8590324c96950417c57fa6ecd1

SELECT 
    uid.uid,
    IFNULL(act_month_total,0) act_month_total,
    IFNULL(act_days_2021,0) act_days_2021,
    IFNULL(act_days_2021_exam,0) act_days_2021_exam,
    IFNULL(act_days_2021_question,0) act_days_2021_question
FROM(
    SELECT uid
    FROM user_info
    WHERE level = 6 OR level = 7
    ) uid
LEFT JOIN 
    (
    SELECT 
        uid,
        COUNT(act_month) act_month_total
    FROM(
        SELECT 
            DISTINCT uid, DATE_FORMAT(start_time,'%Y%m') act_month
        FROM exam_record
        UNION 
        SELECT 
            DISTINCT uid, DATE_FORMAT(submit_time,'%Y%m') act_month
        FROM practice_record
        ) uid_act_month
    GROUP BY uid
    ) act_month_total USING(uid)
LEFT JOIN
    (
    SELECT 
        uid,
        COUNT(act_days_2021) act_days_2021  
    FROM
        (
        SELECT 
            DISTINCT uid, DATE(start_time) act_days_2021
        FROM exam_record
        WHERE YEAR(start_time) = 2021
        UNION 
        SELECT 
            DISTINCT uid, DATE(submit_time) act_days_2021
        FROM practice_record
        WHERE YEAR(submit_time) = 2021
        ) uid_act_days_2021
    GROUP BY uid
    ) act_days_2021 USING(uid)
LEFT JOIN
    (SELECT
        uid,
        COUNT(DISTINCT DATE(start_time)) act_days_2021_exam  
    FROM exam_record
    WHERE YEAR(start_time) = 2021
    GROUP BY uid) act_days_2021_exam USING(uid)
LEFT JOIN
    (SELECT
        uid,
        COUNT(DISTINCT DATE(submit_time)) act_days_2021_question  
    FROM practice_record
    WHERE YEAR(submit_time) = 2021
    GROUP BY uid) act_days_2021_question USING(uid)

ORDER BY act_month_total DESC,act_days_2021 DESC


全部评论

相关推荐

01-08 09:40
中南大学 Java
苏苏加油努力:你的女神不回你消息,并且给别的男生发消息 be like
点赞 评论 收藏
分享
码农烧烤880:兄弟你是我今天看到的最好看的简历(我说的是简历风格跟简历书写)把985 211再搞亮一点。投boss就说;您好,我华科(985)研二在读,本科211。对您的岗位很感兴趣,希望能获得一次投递机会。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务