SELECT shipcountry, GROUPING(shipcountry) AS grpcountry, shipregion , GROUPING(shipregion) AS grpregion, shipcity , GROUPING(shipcity) AS grpcity, COUNT(*) AS numorders FROM Sales.Orders GROUP BY ROLLUP( shipcountry, shipregion, shipcity );
- 5. Grouping and Windowing
- from Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012
- Publisher: Microsoft Press
- Released: December 2012
I this case these extra columns are added to the output and treated by T-SQL like aggregates, meaning they don't have to be in the GROUP clause.
Share this highlighthttp://www.safaribooksonline.com/a/training-kit-exam/60645/