Bird
0
0

Identify the error in this query that tries to calculate a cumulative sum of sales per region:

medium📝 Debug Q14 of 15
PostgreSQL - Window Functions in PostgreSQL
Identify the error in this query that tries to calculate a cumulative sum of sales per region:
SELECT region, sales, SUM(sales) OVER (PARTITION region ORDER BY date) AS running_total FROM sales_data;
ASUM() cannot be used as a window function.
BMissing parentheses around PARTITION BY clause.
CORDER BY cannot be used inside OVER().
DPARTITION keyword should be PARTITION BY.
Step-by-Step Solution
Solution:
  1. Step 1: Check window function syntax

    The correct syntax requires PARTITION BY, not just PARTITION.
  2. Step 2: Validate other parts

    ORDER BY inside OVER() is valid for running totals, and SUM() is allowed as a window function.
  3. Final Answer:

    PARTITION keyword should be PARTITION BY. -> Option D
  4. Quick Check:

    Use PARTITION BY, not PARTITION alone [OK]
Quick Trick: Use PARTITION BY, not just PARTITION [OK]
Common Mistakes:
  • Omitting BY after PARTITION
  • Thinking ORDER BY is invalid in OVER()
  • Believing SUM() can't be a window function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes