Bird
0
0

Identify the error in this query intended to calculate a running total of points ordered by game_date:

medium📝 Debug Q14 of 15
SQL - Advanced Window Functions
Identify the error in this query intended to calculate a running total of points ordered by game_date:
SELECT player_id, points, SUM(points) OVER (PARTITION BY player_id) ORDER BY game_date FROM game_scores;
AORDER BY clause is outside the OVER() function
BPARTITION BY cannot be used with SUM()
CMissing GROUP BY clause
DSUM() cannot be used with window functions
Step-by-Step Solution
Solution:
  1. Step 1: Check placement of ORDER BY

    ORDER BY for running total must be inside OVER(), not outside the function.
  2. Step 2: Understand correct syntax

    Correct syntax: SUM(points) OVER (PARTITION BY player_id ORDER BY game_date).
  3. Final Answer:

    ORDER BY clause is outside the OVER() function -> Option A
  4. Quick Check:

    ORDER BY must be inside OVER() for running totals [OK]
Quick Trick: Put ORDER BY inside OVER() for running totals [OK]
Common Mistakes:
  • Placing ORDER BY outside OVER()
  • Confusing PARTITION BY with GROUP BY
  • Thinking SUM() can't be window function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes