Where did I rank?

Warm-up · window-functions, filtering, joins

Given 3 tables, students(id, name), courses(id, name), grades(id, course_id, student_id, grade),

find the rank of the student 'Ahmed Abbas' in the course 'Database Systems'. The rank is 1 plus

the number of students in that course with a strictly higher grade, so equal grades share a rank.

Output the column (student_rank).

Expected columns

student_rank

Hints

Hint 1 — which rows matter

Only the grades of 'Database Systems' decide this rank. SHOW INDEX FROM grades shows an index on course_id, so MySQL can read just that course's grades instead of all 40,000.

Hint 2 — when the window runs

Window functions are computed after WHERE. RANK() OVER (ORDER BY grade DESC) over one course's grades is the same rank, but filtering on the student's name outside the window means ranking every course first.