Bird
0
0

Given a table sales with columns region, month, and amount, what will this query return?

medium📝 query result Q4 of 15
SQL - Advanced Window Functions
Given a table sales with columns region, month, and amount, what will this query return?
SELECT region, month, amount, SUM(amount) OVER (PARTITION BY region ORDER BY month) AS running_total FROM sales;
AAverage sales amount per month across all regions.
BTotal sales amount for all regions combined.
CA running total of sales amount per region ordered by month.
DSales amount only for the first month in each region.
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the window function usage

    SUM(amount) OVER (PARTITION BY region ORDER BY month) calculates a running total per region ordered by month.
  2. Step 2: Understand output columns

    The query returns each row with region, month, amount, and the cumulative sum of amount within that region up to that month.
  3. Final Answer:

    A running total of sales amount per region ordered by month. -> Option C
  4. Quick Check:

    Window SUM with PARTITION and ORDER BY = running total per group [OK]
Quick Trick: PARTITION BY groups, ORDER BY defines running total order [OK]
Common Mistakes:
  • Thinking it sums all regions together
  • Confusing running total with average
  • Assuming it filters first month only

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes