Bird
0
0

Why might NTH_VALUE return NULL for some rows even if the table has enough rows?

hard📝 Conceptual Q10 of 15
SQL - Advanced Window Functions
Why might NTH_VALUE return NULL for some rows even if the table has enough rows?
ABecause the window frame does not include enough rows to reach the nth position
BBecause NTH_VALUE only works on aggregated data
CBecause the column contains NULL values which cause NTH_VALUE to fail
DBecause NTH_VALUE requires a GROUP BY clause
Step-by-Step Solution
Solution:
  1. Step 1: Understand window frame effect

    NTH_VALUE returns NULL if the window frame for the current row has fewer than n rows.
  2. Step 2: Exclude other reasons

    NTH_VALUE works on row sets, not aggregates; NULL values in column do not cause failure; GROUP BY is not required.
  3. Final Answer:

    Because the window frame does not include enough rows to reach the nth position -> Option A
  4. Quick Check:

    Window frame size affects NTH_VALUE output [OK]
Quick Trick: Window frame size must be ≥ n for NTH_VALUE to return value [OK]
Common Mistakes:
  • Assuming NULL column values cause NTH_VALUE to fail
  • Thinking NTH_VALUE needs GROUP BY
  • Ignoring window frame boundaries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes