Calculating cumulative sales with windowing functions
Suppose you are given the following table showing company sales:
Calculate the cumulative percent of total sales on a given day. Cumulative sales up to a day is calculated adding the total sales of the current day and adding all the prior day total sales. The total sales can be calculated by adding all sales that exist in the table. To get the percent of cumulative total sales, you will need to calculate the cumulative sales and divide by the total sales. The output of the table should look like the example table below.
You can view/query the data in an interactive SQL fiddle here.
Subscribe to premium account to see the solution.Get premium now