Skip
Arish's avatar

218. Practice - FROM Subquery 2


Exercise: Ranked Results

Rank courses by student count.

Solution

sql
1SELECT course, count,
2  (SELECT COUNT(*) FROM (SELECT course, COUNT(*) AS c FROM students GROUP BY course) AS t2
3   WHERE t2.c >= t.count) AS rank
4FROM (
5  SELECT course, COUNT(*) AS count
6  FROM students GROUP BY course
7) AS t;