0
0
SQLquery~5 mins

ROW_NUMBER function in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the ROW_NUMBER() function do in SQL?
It assigns a unique sequential number to each row within a result set, starting at 1 for the first row.
Click to reveal answer
intermediate
How do you reset the row numbering for each group in SQL using ROW_NUMBER()?
Use the PARTITION BY clause inside ROW_NUMBER() to restart numbering for each group.
Click to reveal answer
beginner
Write a simple SQL snippet using ROW_NUMBER() to number rows ordered by salary descending.
SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rank FROM employees;
Click to reveal answer
intermediate
Can ROW_NUMBER() produce ties (same number for multiple rows)? Why or why not?
No, ROW_NUMBER() always gives unique numbers even if values are the same, unlike RANK() which can produce ties.
Click to reveal answer
beginner
What happens if you omit ORDER BY in the ROW_NUMBER() OVER() clause?
The query will fail because ORDER BY is required to define the order for numbering rows.
Click to reveal answer
What does ROW_NUMBER() assign to each row?
AA unique sequential number starting at 1
BThe total count of rows
CThe sum of values in a column
DThe average value of a column
Which clause is used with ROW_NUMBER() to restart numbering for each group?
AGROUP BY
BHAVING
CORDER BY
DPARTITION BY
If two rows have the same value in the ORDER BY column, what does ROW_NUMBER() do?
AAssigns the same number to both rows
BAssigns different unique numbers to each row
CSkips numbering those rows
DReturns an error
What is required inside the OVER() clause for ROW_NUMBER() to work?
AORDER BY clause
BGROUP BY clause
CWHERE clause
DHAVING clause
Which function can produce ties in numbering rows?
AROW_NUMBER()
BCOUNT()
CRANK()
DSUM()
Explain how ROW_NUMBER() works and how you can restart numbering for each group.
Think about numbering rows like giving each person a unique ticket number, and restarting numbering for each team.
You got /4 concepts.
    Describe the difference between ROW_NUMBER() and RANK() functions.
    Consider how a race ranking might handle ties versus unique positions.
    You got /4 concepts.