Bird
0
0

What is wrong with this SQL query?

medium📝 Debug Q6 of 15
SQL - Advanced Window Functions
What is wrong with this SQL query?
SELECT employee_id, NTH_VALUE(salary, -1) OVER (ORDER BY salary) AS nth_salary FROM Employees;
AThe position argument for NTH_VALUE cannot be negative.
BThe ORDER BY clause is missing a PARTITION BY clause.
CNTH_VALUE requires a GROUP BY clause to work properly.
DThe query should use FIRST_VALUE instead of NTH_VALUE.
Step-by-Step Solution
Solution:
  1. Step 1: Check the NTH_VALUE syntax

    The second argument (position) must be a positive integer indicating which row's value to return.
  2. Step 2: Analyze the query

    Using -1 as the position is invalid and causes an error.
  3. Final Answer:

    The position argument for NTH_VALUE cannot be negative. -> Option A
  4. Quick Check:

    Position must be positive integer [OK]
Quick Trick: NTH_VALUE position must be positive integer [OK]
Common Mistakes:
  • Using zero or negative numbers as the position argument
  • Assuming PARTITION BY is mandatory with NTH_VALUE
  • Confusing NTH_VALUE with aggregate functions requiring GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes