PostgreSQL - Window Functions in PostgreSQLWhich 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 salesBSUM(sales) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING)CSUM(sales) GROUP BY date ORDER BY salesDSUM(sales) OVER (PARTITION BY date ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING)Check Answer
Step-by-Step SolutionSolution:Step 1: Understand cumulative sum conceptCumulative sum adds all previous rows up to current row ordered by date.Step 2: Check window frame syntaxROWS UNBOUNDED PRECEDING means from first row to current row, correct for cumulative sum.Final Answer:SUM(sales) OVER (ORDER BY date ROWS UNBOUNDED PRECEDING) -> Option BQuick 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 sumsConfusing GROUP BY with window functionsIncorrect window frame boundaries
Master "Window Functions in PostgreSQL" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Common Table Expressions - Recursive CTE for hierarchical data - Quiz 8hard Common Table Expressions - Recursive CTE for graph traversal - Quiz 15hard Common Table Expressions - CTE materialization behavior - Quiz 12easy Full-Text Search - Ranking with ts_rank - Quiz 6medium JSON and JSONB - Arrow operators (-> and ->>) - Quiz 12easy JSON and JSONB - Why JSON support matters in PostgreSQL - Quiz 1easy Joins in PostgreSQL - LEFT JOIN and RIGHT JOIN - Quiz 14medium Subqueries in PostgreSQL - Subqueries in FROM (derived tables) - Quiz 1easy Subqueries in PostgreSQL - LATERAL subqueries - Quiz 11easy Window Functions in PostgreSQL - LAG and LEAD for row comparison - Quiz 4medium