Bird
0
0

Why does this query cause an error?

medium📝 Debug Q7 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Why does this query cause an error?
SELECT region, SUM(amount) FROM sales GROUP BY CUBE region;
ASUM() cannot be used with CUBE
BMissing parentheses around the column in CUBE
CGROUP BY cannot use functions like CUBE
Dregion column does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Check CUBE syntax

    CUBE requires parentheses around the list of columns: GROUP BY CUBE(region).
  2. Step 2: Identify error in query

    The query misses parentheses around region inside CUBE, causing syntax error.
  3. Final Answer:

    Missing parentheses around the column in CUBE -> Option B
  4. Quick Check:

    CUBE syntax = GROUP BY CUBE(cols) [OK]
Quick Trick: Always use parentheses with CUBE columns [OK]
Common Mistakes:
  • Omitting parentheses in CUBE
  • Using CUBE syntax like simple GROUP BY
  • Confusing CUBE with other operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes