Bird
0
0

Which of the following is the correct syntax to calculate the cumulative sum of sales ordered by date in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Window Functions in PostgreSQL
Which of the following is the correct syntax to calculate the cumulative sum of sales ordered by date in PostgreSQL?
ASUM(sales) PARTITION BY date ORDER BY sales
BSUM(sales) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING)
CSUM(sales) GROUP BY date ORDER BY sales
DSUM(sales) OVER (PARTITION BY date ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)
Step-by-Step Solution
Solution:
  1. Step 1: Understand cumulative sum concept

    Cumulative sum adds all previous rows up to current row ordered by date.
  2. Step 2: Check window frame syntax

    ROWS UNBOUNDED PRECEDING means from first row to current row, correct for cumulative sum.
  3. Final Answer:

    SUM(sales) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING) -> Option B
  4. Quick Check:

    Cumulative sum uses SUM() OVER with ORDER BY and UNBOUNDED PRECEDING [OK]
Quick Trick: Use ROWS UNBOUNDED PRECEDING for cumulative sums [OK]
Common Mistakes:
  • Using PARTITION BY without ORDER BY for cumulative sums
  • Confusing GROUP BY with window functions
  • Incorrect window frame boundaries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes