Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Identify the error in this query:
SELECT category, region, SUM(amount) FROM sales_data GROUP BY GROUPING SETS ((category), region);
AThe SELECT clause must include GROUPING() function.
BSUM(amount) cannot be used with GROUPING SETS.
CGROUPING SETS cannot include more than one column.
DThe second grouping set 'region' is not enclosed in parentheses.
Step-by-Step Solution
Solution:
  1. Step 1: Review GROUPING SETS syntax

    Each grouping set must be enclosed in parentheses.
  2. Step 2: Analyze the query

    The query has GROUPING SETS ((category), region) where 'region' is not in parentheses.
  3. Step 3: Identify the error

    Missing parentheses around 'region' causes syntax error.
  4. Final Answer:

    The second grouping set 'region' is not enclosed in parentheses. -> Option D
  5. Quick Check:

    Each grouping set requires parentheses [OK]
Quick Trick: Always enclose each grouping set in parentheses [OK]
Common Mistakes:
  • Forgetting parentheses around single-column grouping sets
  • Misusing aggregate functions with GROUPING SETS
  • Assuming GROUPING() function is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes