This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
ProductID, | |
SalesDate, | |
OrderQty, | |
SUM(OrderQty) OVER ( | |
ORDER BY SalesDate | |
ROWS BETWEEN 2 PRECEDING AND 2 FOLLOWING | |
) AS RollingSumOrderQty | |
FROM sales_data | |
ORDER BY ProductID, SalesDate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
FORMAT(SalesDate,'MMM') AS Month, | |
Amount, | |
AVG(Amount)OVER(PARTITION BY DATEPART(Month,SalesDate)) AS Avg_amount_per_transaction | |
FROM sales_data |