Bird
0
0

Why does the LAG function return NULL for the first row in a partition or ordered set?

hard📝 Conceptual Q10 of 15
SQL - Advanced Window Functions
Why does the LAG function return NULL for the first row in a partition or ordered set?
ABecause the first row is always filtered out
BBecause LAG only works on even-numbered rows
CBecause there is no previous row to access
DBecause the first row has a default value of zero
Step-by-Step Solution
Solution:
  1. Step 1: Understand LAG behavior on first row

    LAG looks back to previous rows; the first row has no previous row.
  2. Step 2: Explain NULL result

    Since no previous row exists, LAG returns NULL for the first row by default.
  3. Final Answer:

    Because there is no previous row to access -> Option C
  4. Quick Check:

    LAG returns NULL when no previous row exists [OK]
Quick Trick: First row has no previous row, so LAG returns NULL [OK]
Common Mistakes:
  • Thinking first row is filtered out
  • Assuming LAG skips first row
  • Believing default is zero instead of NULL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes