← Back to Window Functions
Question 50
Number the Students by GPA
Number the Students by GPA
Give every student with a knowngpaa position withROW_NUMBER(): returnrn,first_name,last_nameandgpa, numbering from the highestgpadown and breaking ties onidso each number is fixed. Leave out the three students whosegpais NULL and sort byrn.
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
Sign in to use hintsTopics:
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.