Bird
0
0

Identify the issue in this query intended to calculate a running total of amount ordered by transaction_date across all rows:

medium📝 Debug Q7 of 15
SQL - Advanced Window Functions
Identify the issue in this query intended to calculate a running total of amount ordered by transaction_date across all rows:
SELECT id, amount, SUM(amount) OVER (PARTITION BY category ORDER BY transaction_date) AS running_total FROM sales;
AORDER BY clause inside OVER() is invalid syntax
BMissing GROUP BY clause to aggregate amounts
CUsing PARTITION BY category splits the running total by category, not across all rows
DSUM() cannot be used with OVER() for running totals
Step-by-Step Solution
Solution:
  1. Step 1: Understand PARTITION BY effect

    PARTITION BY divides rows into groups; running total restarts per group.
  2. Step 2: Goal is running total across all rows

    Including PARTITION BY category causes separate totals per category, not a global running total.
  3. Final Answer:

    Using PARTITION BY category splits the running total by category, not across all rows -> Option C
  4. Quick Check:

    PARTITION BY limits running total scope [OK]
Quick Trick: PARTITION BY resets running total per group [OK]
Common Mistakes:
  • Confusing PARTITION BY with GROUP BY
  • Assuming PARTITION BY is optional for running totals
  • Misunderstanding window function syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes