Bird
0
0

Find the problem in this query:

medium📝 Debug Q7 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Find the problem in this query:
SELECT department, product, SUM(sales) FROM sales_data GROUP BY GROUPING SETS ((department, product), (department));
ASUM() cannot be used with multiple grouping sets
BThe query is valid and will run without errors
CGROUPING SETS cannot have overlapping grouping sets
DGROUP BY must include all columns in SELECT
Step-by-Step Solution
Solution:
  1. Step 1: Review GROUPING SETS usage

    GROUPING SETS can include overlapping sets like (department, product) and (department).
  2. Step 2: Check aggregation and SELECT columns

    SUM() is valid, and SELECT columns match grouping sets.
  3. Final Answer:

    The query is valid and will run without errors -> Option B
  4. Quick Check:

    Overlapping grouping sets are allowed in GROUPING SETS [OK]
Quick Trick: GROUPING SETS can include overlapping column sets [OK]
Common Mistakes:
  • Thinking overlapping sets cause errors
  • Assuming SUM() is restricted with multiple groupings
  • Believing all SELECT columns must be in every grouping set

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes