Bird
0
0

Given the table sales with columns region and amount, what will the query SELECT region, amount, SUM(amount) OVER (PARTITION BY region ORDER BY amount) AS running_total FROM sales; return?

medium📝 query result Q4 of 15
PostgreSQL - Window Functions in PostgreSQL
Given the table sales with columns region and amount, what will the query SELECT region, amount, SUM(amount) OVER (PARTITION BY region ORDER BY amount) AS running_total FROM sales; return?
ASum of amount ignoring region and order
BTotal sales amount for all regions combined
CA running total of sales amount per region ordered by amount
DCount of sales per region
Step-by-Step Solution
Solution:
  1. Step 1: Analyze SUM() OVER with PARTITION and ORDER

    The query calculates a running total of amount within each region, ordered by amount.
  2. Step 2: Understand output rows

    Each row shows region, amount, and cumulative sum of amounts up to that row in the region.
  3. Final Answer:

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

    SUM() OVER (PARTITION BY region ORDER BY amount) = Running total per region [OK]
Quick Trick: ORDER BY inside OVER() defines running total order [OK]
Common Mistakes:
  • Ignoring ORDER BY causing total sum instead of running total
  • Confusing COUNT() with SUM()
  • Assuming no partition means total sum

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes