Calculating quarterly moving average of revenue in SQL
Suppose you're working with a large conglomerate and are trying to aggregate revenue across all divisions to highlight the overall trend. The table you're querying off of is called allRevenue, sample schema is shown below.
Given the above, can you write a SQL query that calculates 4-quarter rolling average revenue, cut by each quarter? The output query should only have 2 columns: 'quarter' and 'revenue' (where revenue is the trailing 4-quarter average). You can assume you have access to a function similar to this.
Subscribe to premium account to see the solution.Get premium now