Bird
0
0

Which of the following is the correct syntax to calculate a running total of sales using a window function?

easy📝 Syntax Q12 of 15
SQL - Advanced Window Functions
Which of the following is the correct syntax to calculate a running total of sales using a window function?
ASELECT SUM(sales) OVER (ORDER BY date) AS running_total FROM sales_data;
BSELECT SUM(sales) GROUP BY date ORDER BY running_total FROM sales_data;
CSELECT RUNNING_TOTAL(sales) FROM sales_data ORDER BY date;
DSELECT sales + PREVIOUS(sales) FROM sales_data;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct window function syntax

    SUM() OVER (ORDER BY column) computes running total ordered by that column.
  2. Step 2: Check other options for syntax errors

    The other options use invalid SQL syntax or functions that don't exist.
  3. Final Answer:

    SELECT SUM(sales) OVER (ORDER BY date) AS running_total FROM sales_data; -> Option A
  4. Quick Check:

    SUM() OVER (ORDER BY ...) = running total [OK]
Quick Trick: Use SUM() OVER (ORDER BY ...) for running totals [OK]
Common Mistakes:
  • Using GROUP BY instead of OVER()
  • Trying non-existent functions like RUNNING_TOTAL()
  • Adding values manually without window syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes