Using groups

Groups are what make aggregate queries even more useful and readable for users. This is why groups are used heavily in reporting. For statistical purposes, groups help to calculate aggregations across sections in data to divide the data in accordance with its meaning. Let's go straight to an example. We have a database called AdventureWorks. This database contains three tables in the Production schema: ProductCategory, ProductSubcategoryand Product. Products are assigned to subcategories, and subcategories are then assigned to categories, so the three tables form a simple hierarchy together. To explore the tables, execute the following query:

SELECT  c.ProductCategoryID  , c.Name AS CategoryName  , psc.ProductSubcategoryID , psc.Name ...

Get Hands-On Data Science with SQL Server 2017 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.