Bird
0
0

Which of the following is the correct syntax to assign row numbers ordered by salary in descending order?

easy📝 Syntax Q12 of 15
SQL - Window Functions Fundamentals
Which of the following is the correct syntax to assign row numbers ordered by salary in descending order?
ASELECT ROW_NUMBER() FROM employees ORDER BY salary DESC;
BSELECT ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees;
CSELECT ROW_NUMBER() ORDER BY salary DESC FROM employees;
DSELECT ROW_NUMBER(salary DESC) FROM employees;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct ROW_NUMBER() syntax

    The correct syntax uses ROW_NUMBER() OVER (ORDER BY column) to assign numbers ordered by a column.
  2. Step 2: Check each option

    Only SELECT ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees; correctly uses OVER (ORDER BY salary DESC). The other options omit the OVER clause, pass arguments directly to ROW_NUMBER(), or misplace the ORDER BY clause.
  3. Final Answer:

    SELECT ROW_NUMBER() OVER (ORDER BY salary DESC) AS rn FROM employees; -> Option B
  4. Quick Check:

    ROW_NUMBER() needs OVER with ORDER BY [OK]
Quick Trick: ROW_NUMBER() must use OVER() with ORDER BY inside [OK]
Common Mistakes:
  • Omitting OVER() clause
  • Placing ORDER BY outside OVER()
  • Passing column directly to ROW_NUMBER()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes