Bird
0
0

Which of the following is the correct syntax to calculate a running total of sales_amount ordered by sale_date using the OVER clause?

easy📝 Syntax Q3 of 15
SQL - Window Functions Fundamentals
Which of the following is the correct syntax to calculate a running total of sales_amount ordered by sale_date using the OVER clause?
ASELECT SUM(sales_amount) FROM sales ORDER BY sale_date OVER();
BSELECT SUM(sales_amount) OVER (ORDER BY sale_date) FROM sales;
CSELECT SUM(sales_amount) OVER sale_date ORDER BY FROM sales;
DSELECT SUM(sales_amount) ORDER BY sale_date OVER() FROM sales;
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct OVER clause syntax

    The OVER clause must follow the aggregate function and include ORDER BY inside parentheses.
  2. Step 2: Check each option's syntax

    SELECT SUM(sales_amount) OVER (ORDER BY sale_date) FROM sales; correctly places OVER (ORDER BY sale_date) after SUM(sales_amount). Others misuse syntax or order.
  3. Final Answer:

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

    SUM() OVER (ORDER BY ...) = running total syntax [OK]
Quick Trick: OVER clause goes right after aggregate function with ORDER BY [OK]
Common Mistakes:
  • Placing ORDER BY outside OVER clause
  • Omitting parentheses after OVER
  • Incorrect keyword order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes