Bird
0
0

Which of the following is the correct syntax to calculate a row number for each employee within their department using PARTITION BY?

easy📝 Syntax Q3 of 15
SQL - Window Functions Fundamentals
Which of the following is the correct syntax to calculate a row number for each employee within their department using PARTITION BY?
AROW_NUMBER() OVER (PARTITION BY Department ORDER BY EmployeeID)
BROW_NUMBER() PARTITION BY Department ORDER BY EmployeeID
CROW_NUMBER(PARTITION BY Department ORDER BY EmployeeID)
DROW_NUMBER() WHERE Department ORDER BY EmployeeID
Step-by-Step Solution
Solution:
  1. Step 1: Recall correct syntax for ROW_NUMBER with PARTITION BY

    The correct syntax places PARTITION BY and ORDER BY inside OVER parentheses: ROW_NUMBER() OVER (PARTITION BY Department ORDER BY EmployeeID).
  2. Step 2: Identify syntax errors in other options

    Options A and B miss OVER keyword or parentheses; D uses WHERE incorrectly.
  3. Final Answer:

    ROW_NUMBER() OVER (PARTITION BY Department ORDER BY EmployeeID) -> Option A
  4. Quick Check:

    ROW_NUMBER syntax = ROW_NUMBER() OVER (PARTITION BY ... ORDER BY ...) [OK]
Quick Trick: Always use OVER() with PARTITION BY and ORDER BY inside [OK]
Common Mistakes:
  • Omitting OVER keyword
  • Placing PARTITION BY outside parentheses
  • Using WHERE instead of PARTITION BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes