Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
SQL - Advanced Query Patterns
Identify the error in this query:
SELECT category, SUM(CASE category = 'Books' THEN 1 ELSE 0 END) AS books_count FROM products GROUP BY category;
AGROUP BY should include books_count
BSUM cannot be used with CASE
CMissing WHEN keyword in CASE statement
Dcategory column missing in SELECT
Step-by-Step Solution
Solution:
  1. Step 1: Check CASE syntax

    CASE requires WHEN before condition; here it is missing.
  2. Step 2: Validate other parts

    GROUP BY and SELECT columns are correct; SUM with CASE is valid.
  3. Final Answer:

    Missing WHEN keyword in CASE statement -> Option C
  4. Quick Check:

    CASE syntax requires WHEN before condition [OK]
Quick Trick: CASE must have WHEN before condition [OK]
Common Mistakes:
  • Omitting WHEN keyword
  • Adding aggregate columns to GROUP BY unnecessarily
  • Misunderstanding SUM with CASE usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes