Created
October 12, 2022 20:57
-
-
Save thoolihan/2f9d2e7b82901631d6da65421114d5b2 to your computer and use it in GitHub Desktop.
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
WITH cteRevenueDays(Orders, StoreDate, Revenue) AS ( | |
SELECT COUNT(SalesOrderID) AS Orders | |
,CAST(OrderDate AS DATE) as [StoreDate] | |
,SUM(SubTotal) AS Revenue | |
FROM [AdventureWorks2019].[Sales].[SalesOrderHeader] | |
WHERE DATEPART(YEAR, CAST(OrderDate as DATE)) = 2011 | |
AND DATEPART(MONTH, CAST(OrderDate as DATE)) = 7 | |
GROUP BY CAST(OrderDate as DATE) | |
) SELECT | |
StoreDate | |
,DATEPART(WEEK, StoreDate) AS [StoreWeek] | |
,Orders | |
,ROUND(Revenue, 2) | |
,ROUND(SUM(Revenue) OVER(PARTITION BY DATEPART(WEEK, StoreDate) ORDER BY StoreDate),2) AS WeekToDateRevenue | |
,ROUND(SUM(Revenue) OVER(ORDER BY StoreDate),2) AS MonthToDateRevenue | |
FROM cteRevenueDays; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment