Bird
0
0

What will the following query output given table seq with values (10, 11, 13, 14, 15)?

medium📝 query result Q5 of 15
SQL - Advanced Query Patterns
What will the following query output given table seq with values (10, 11, 13, 14, 15)?
SELECT num + 1 AS gap_start FROM seq WHERE num + 1 <> LEAD(num) OVER (ORDER BY num);
A12
B11
C14
D15
Step-by-Step Solution
Solution:
  1. Step 1: Identify next values using LEAD()

    Values: 10,11,13,14,15; Next: 11,13,14,15,NULL
  2. Step 2: Find where num + 1 differs from next num

    10+1=11 equals 11 (no gap); 11+1=12 not equal 13 (gap 12)
  3. Final Answer:

    12 -> Option A
  4. Quick Check:

    Gap found at 12 [OK]
Quick Trick: Gap is num+1 when it differs from next num [OK]
Common Mistakes:
  • Choosing existing numbers
  • Ignoring last row
  • Misreading LEAD() output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes