bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1112. Highest Grade For Each Student

1112. Highest Grade For Each Student

Leetcode Solutions

Window Function Approach

  1. Use the DENSE_RANK() window function to assign a rank to each student's grade, partitioned by student_id and ordered by grade descending and course_id ascending.
  2. From the ranked results, filter out the records where the rank is 1, which corresponds to the highest grade for each student.
  3. Order the final result by student_id in ascending order to match the required output format.
erDiagram
    Enrollments {
        int student_id
        int course_id
        int grade
        student_id course_id PK
    }

Aggregation & Self-Join Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...