题解 | #分别满足两个活动的人#

分别满足两个活动的人

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

SELECT DISTINCT uid, 'activity1' AS sctivity
FROM exam_record
WHERE score >= 85 AND YEAR(submit_time)=2021
UNION
SELECT DISTINCT uid, 'activity2' AS sctivity
FROM (
    SELECT
        uid, start_time, submit_time, score, 
        TIMESTAMPDIFF(MINUTE,start_time,submit_time) AS spend_time,
        IF(TIMESTAMPDIFF(MINUTE,start_time,submit_time) < (duration/2),1,0) AS early_finish,
        difficulty
    FROM exam_record
    JOIN examination_info USING(exam_id)
) AS er_ei
WHERE difficulty='hard' AND score > 80 AND YEAR(submit_time)=2021
GROUP BY uid
HAVING SUM(early_finish) >= 1
ORDER BY uid;

全部评论

相关推荐

喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务