Leetcode - 1112. Highest Grade For Each Student
Photo by Redd F / Unsplash
Coding Test

Leetcode - 1112. Highest Grade For Each Student

Indo Yoon

문제

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 Ranks AS (
    SELECT *, RANK() OVER(
        PARTITION BY student_id
        ORDER BY grade DESC
    ) as 'rank'
    FROM Enrollments
)
# SELECT Enrollments.*
# FROM Enrollments, Ranks
SELECT student_id, MIN(course_id) as course_id, grade
FROM Ranks
WHERE Ranks.rank = 1
GROUP BY student_id