Bird
0
0

Identify the error in this query to find gaps:

medium📝 Debug Q6 of 15
SQL - Advanced Query Patterns
Identify the error in this query to find gaps:
SELECT num + 1 AS missing FROM seq WHERE num + 1 = LEAD(num) OVER (ORDER BY num);
Anum + 1 should be replaced with num - 1
BMissing GROUP BY clause
CUsing '=' instead of '<>' causes no gaps to be found
DLEAD() cannot be used without PARTITION BY
Step-by-Step Solution
Solution:
  1. Step 1: Understand the condition used

    The query checks where num + 1 equals the next num, which means no gap.
  2. Step 2: Correct condition for gaps

    To find gaps, we want num + 1 not equal to next num, so '<>' is needed.
  3. Final Answer:

    Using '=' instead of '<>' causes no gaps to be found -> Option C
  4. Quick Check:

    Equality check hides gaps [OK]
Quick Trick: Use '<>' to detect gaps, not '=' [OK]
Common Mistakes:
  • Using '=' instead of '<>'
  • Adding unnecessary GROUP BY
  • Misusing LEAD() syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes