CJCoding With Joseph
15free / daySign inCreate account

Number the Students by GPA

Give every student with a known gpa a position with ROW_NUMBER(): return rn, first_name, last_name and gpa, numbering from the highest gpa down and breaking ties on id so each number is fixed. Leave out the three students whose gpa is NULL and sort by rn.

Expected result:

+----+------------+-----------+------+
| rn | first_name | last_name |  gpa |
+----+------------+-----------+------+
|  1 | Evelyn     | Park      | 3.98 |
|  2 | Sophia     | Rossi     | 3.92 |
|  3 | Grace      | Lee       | 3.88 |
|  4 | Ava        | Patel     |  3.8 |
|  5 | Mia        | Haddad    |  3.8 |
|  6 | Emily      | Zhang     | 3.72 |
|  7 | Charlotte  | Dubois    | 3.67 |
|  8 | Scarlett   | Johnson   |  3.6 |
|  9 | Harper     | Singh     | 3.55 |
| 10 | Zoe        | Campbell  |  3.5 |
+----+------------+-----------+------+
(showing 10 of 27 rows)
Hints3 available
Topics:
Window Functions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sel, ins, desc)

Results

Run your SQL to see every statement's output here, then how it compares with the expected answer.

Not sure what is in a table? SHOW TABLES lists them and DESCRIBE students shows the columns — or open the database browser on the left.