1SELECT
2 DATEADD(DAY, 7 - DATEPART(WEEKDAY, orderDate), CAST(orderDate AS DATE)) AS ordersPerWeek,
3 sum(orderAmount) AS orderSumForGrouping,
4 count(1) AS numberOfOrdersWithinGrouping
5FROM @table o
6GROUP BY DATEADD(DAY, 7 - DATEPART(WEEKDAY, orderDate), CAST(orderDate AS DATE))
7