Training on Aggregation Strategies for the SQL Server Queries Certification course. 70-461
See http://stevestedman.com/2015/01/aggregating-data-and-aggregation-strategies/ for more information on aggregation strategies.
3. OVER
Introduced in SQL Server 2005
Aggregation without a GROUP BY
Also know as “Window Functions” or “Windowing
Functions”.
4. Multiple grouping, with one query?
SELECT Category, SUM(UnitRetail), COUNT(*)
FROM [dbo].[Inventory]
GROUP BY Category;
SELECT UnitRetail, SUM(UnitRetail), COUNT(*)
FROM [dbo].[Inventory]
GROUP BY UnitRetail;
5. Window Functions
SELECT Category,
SUM(UnitRetail) OVER (PARTITION BY Category),
COUNT(*) OVER (PARTITION BY Category),
UnitRetail,
SUM(UnitRetail) OVER(PARTITION BY UnitRetail),
COUNT(*) OVER(PARTITION BY UnitRetail)
FROM [dbo].[Inventory];
.