Grouping Sets

Grouping Sets.

Last updated:

Warning: Review and test in a non-production environment before running.

Back to results

SELECT null Name,Size,MAX(SellStartDate)
FROM [Production].[Product]
GROUP BY Size
UNION ALL
SELECT Name,null DatabaseSize, MAX(SellStartDate)
FROM [Production].[Product] 
GROUP BY Name
order by 1

-- Use GROUPING SETS on single SELECT statement
SELECT Name,Size,MAX(SellStartDate)
FROM [Production].[Product] 
GROUP BY GROUPING SETS ((Name), (Size))
order by 1