Bird
0
0

Which of the following is the correct syntax to calculate a running total of sales ordered by sale_date?

easy📝 Syntax Q12 of 15
SQL - Advanced Window Functions
Which of the following is the correct syntax to calculate a running total of sales ordered by sale_date?
ASELECT sales, SUM(sales) OVER (PARTITION BY sale_date) FROM sales_table;
BSELECT sales, SUM(sales) OVER (ORDER BY sale_date) FROM sales_table;
CSELECT sales, SUM(sales) FROM sales_table ORDER BY sale_date;
DSELECT sales, SUM(sales) OVER () ORDER BY sale_date FROM sales_table;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct use of SUM() OVER()

    Running total requires SUM() OVER with ORDER BY clause inside OVER().
  2. Step 2: Check each option's syntax

    SELECT sales, SUM(sales) OVER (ORDER BY sale_date) FROM sales_table; uses SUM(sales) OVER (ORDER BY sale_date), which is correct syntax for running total.
  3. Final Answer:

    SELECT sales, SUM(sales) OVER (ORDER BY sale_date) FROM sales_table; -> Option B
  4. Quick Check:

    SUM() OVER (ORDER BY ...) = running total syntax [OK]
Quick Trick: Use SUM() OVER (ORDER BY column) for running totals [OK]
Common Mistakes:
  • Using PARTITION BY instead of ORDER BY for running total
  • Omitting OVER() clause
  • Placing ORDER BY outside OVER()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes