Leetcode Problem 1412. Find the Quiet Students in All Exams

1412. Find the Quiet Students in All Exams

Leetcode Solutions

Identifying Quiet Students Using Window Functions and Conditional Aggregation

  1. Use a common table expression (CTE) or a subquery to calculate two ranks for each score in the Exam table: one for the highest score (desc_rk) and one for the lowest score (asc_rk) using the RANK() window function partitioned by exam_id.
  2. Join the CTE or subquery with the Student table on student_id to get student names.
  3. Group the results by student_id and student_name.
  4. Use the HAVING clause to filter out students who have a minimum rank of 1 in either desc_rk or asc_rk, which indicates they have scored the highest or lowest in at least one exam.
  5. Order the final result by student_id.

erDiagram
    Student {
        int student_id PK
        varchar student_name
    }
    Exam {
        int exam_id PK
        int student_id PK
        int score
    }
    Student ||--o{ Exam : has

Identifying Quiet Students Using Subqueries and Conditional Aggregation

Ask Question

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

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...