Bird
0
0

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

medium📝 Debug Q14 of 15
SQL - Advanced Window Functions
Identify the error in this SQL query that tries to calculate a cumulative sum of sales per region:
SELECT region, sales, SUM(sales) OVER (PARTITION region ORDER BY date) AS cumulative_sales FROM sales_data;
AMissing parentheses around PARTITION BY clause.
BIncorrect keyword; should be PARTITION BY instead of PARTITION.
CORDER BY cannot be used inside window functions.
DSUM() cannot be used as a window function.
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; SUM() is valid as window function.
  3. Final Answer:

    Incorrect keyword; should be PARTITION BY instead of PARTITION. -> Option B
  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 window functions
  • Believing SUM() can't be a window function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes