Bird
0
0

Given the table sales with columns id, amount, what is the output of this query?

medium📝 query result Q13 of 15
SQL - Window Functions Fundamentals
Given the table sales with columns id, amount, what is the output of this query?
SELECT id, amount, SUM(amount) OVER (ORDER BY id) AS running_total FROM sales ORDER BY id;
AThe query returns an error due to missing GROUP BY.
BEach row shows id, amount, and total sum of all amounts repeated.
CEach row shows id, amount, and a running total of amounts ordered by id.
DRows are grouped by id with sum of amounts per group.
Step-by-Step Solution
Solution:
  1. Step 1: Understand SUM() OVER (ORDER BY id)

    This calculates a running total of amount, adding amounts in order of id for each row.
  2. Step 2: Analyze output per row

    Each row shows its id, amount, and the sum of amounts from first id up to current id.
  3. Final Answer:

    Each row shows id, amount, and a running total of amounts ordered by id. -> Option C
  4. Quick Check:

    SUM() OVER with ORDER BY = running total [OK]
Quick Trick: SUM() OVER(ORDER BY) gives running totals, not grouped sums [OK]
Common Mistakes:
  • Thinking it sums all rows for each row
  • Expecting GROUP BY to be required
  • Confusing running total with grouped sum

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes