Data analysis: How to perform cumulative analysis over time

Cumulative analysis requirements

In daily data analysis, we often encounter the need for statistics based on time, such as monthly sales statistics. For this type of demand, we can use SQL on the Yanhuang Data Platform to sum up the sales data by time (month) and obtain the sales statistics by time (month) as shown below.

In some cases, we want to see the cumulative sales of the entire year by time (month) to judge whether the established goal has been achieved at a certain point in time.

In this case, we need to use the window function provided by Yanhuang Data Platform to achieve this.

Window function implements analysis accumulated over time

Using the above SQL, sales are accumulated by month.

Where sum("sales") is the sum of the following over() windows.

The rows between unbounded preceding and current row in the window specify that the processing window is unlimited from the current row forward, that is, accumulated from the beginning to the current month.

After the SQL is executed, an additional column "Cumulative Sales" is generated. The data in this column is the cumulative sales from the beginning of the year to the current month.

Guess you like

Origin blog.csdn.net/Yhpdata888/article/details/131582885
Recommended