Search⌘ K

Computing Weekly Changes

Explore how to compute weekly percentage differences between daily dollar values using SQL window functions in PostgreSQL. Understand the use of common table expressions and the lag() function to analyze week-over-week changes efficiently, preparing you to handle time-based data analytics tasks.

Let’s assume that the analytics department now wants us to add a weekly difference for each day of the result. More specifically, we want to add a column with the evolution as a percentage of the dollars column between the day of the value and the same day of the previous week.

Use case: Computing weekly changes

We’re taking the “week over week percentage difference” example because it’s a classic analytics need, though perhaps mostly in ...