Skip to content
SQLSimplified
Data AnalystQuestion 16 of 57

Ranking without Gaps (DENSE_RANK)

Problem

The dean wants a leaderboard of courses sorted by credits. If there is a tie, they should get the same rank, and the next rank should not skip a number. Show course name, credits, and their dense rank named rank.

Database Schema

Table: students

  • `id` (INT): Unique identifier for the student.
  • `name` (VARCHAR): Full name of the student.
  • `grade_level` (INT): The student's current grade level (9-12).
  • `enrollment_year` (INT): The year the student enrolled.

Table: courses

  • `id` (INT): Unique identifier for the course.
  • `name` (VARCHAR): Name of the course.
  • `subject` (VARCHAR): Subject area (e.g., Math, Science).
  • `credits` (INT): Number of course credits.

Table: grades

  • `id` (INT): Unique identifier for the grade entry.
  • `student_id` (INT): Foreign key referencing the student.
  • `course_id` (INT): Foreign key referencing the course.
  • `score` (INT): Numeric score (0-100).
  • `term` (VARCHAR): Term of the grade (e.g., Fall 2022).

Try It

Loading playground environment...

Hint

Solution