SQL/LeetCode

[LeetCode] 1934. Confirmation Rate

yeyeyep 2025. 2. 21. 15:52

 

 

[문제]

이미지를 누르면 문제 링크로 넘어갑니다

 

 

[MySQL]

WITH Action_cnt AS (
    SELECT s.user_id
        , c.action
        , CASE WHEN c.action = 'confirmed' THEN 1
                ELSE 0
            END AS action_cnt
    FROM Signups AS s
        LEFT JOIN Confirmations AS c ON s.user_id = c.user_id
)

SELECT user_id
     , ROUND(SUM(action_cnt) / COUNT(*), 2) AS confirmation_rate
FROM Action_cnt
GROUP BY user_id