Leetcode - 578. Get Highest Answer Rate Question

문제

Loading...
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

정답

WITH Up AS (
SELECT question_id, COUNT(question_id) AS show_count
    FROM SurveyLog
    WHERE action = 'show'
    GROUP BY question_id
)
SELECT question_id AS survey_log
FROM (
    SELECT Up.question_id, answer_count / show_count as rate FROM Up
    LEFT JOIN (
        SELECT question_id, COUNT(question_id) as answer_count
        FROM SurveyLog
        WHERE action = 'answer'
        GROUP BY question_id
        ) AS Ans
    ON Up.question_id = Ans.question_id
    GROUP BY Up.question_id
    ORDER BY rate DESC, question_id
) AS temp
LIMIT 1