I liked it very much. I would like to see more articles like this on the near future. My only "negative" comment is I was reading the article and "copy and paste" the source code and it has a lot typos, here is the code will run:
SELECT
Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
WITH ROLLUP;
SELECT Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
order by Cust.country;
GROUP BY clause.
SELECT
Cust.country ,
Cat.CategoryName ,
Count(*) AS ProductsBought,
GROUPING(Cust.country) AS SubtotalForCountries,
GROUPING(Cat.CategoryName) AS SubtotalForCategories
FROM dbo.Customers AS Cust
INNER JOIN dbo.Orders AS Ord
ON Cust.CustomerId = Ord.CustomerId
INNER JOIN dbo.[Order Details] AS OrdDet
ON Ord.OrderId = OrdDet.OrderId
INNER JOIN dbo.Products AS Prod
ON OrdDet.ProductId = Prod.ProductId
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
GROUP BY
Cust.Country ,
Cat.CategoryName
WITH CUBE ;
SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY
Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice);
SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY
Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice)
BY Cat.CategoryName;
SELECT
Prod.ProductId ,
Prod.ProductName ,
Cat.CategoryName ,
Prod.UnitsInStock * Prod.UnitPrice AS StockValue
FROM dbo.Products AS Prod
INNER JOIN dbo.Categories AS Cat
ON Prod.CategoryId = Cat.CategoryId
ORDER BY Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice)
BY Cat.CategoryName
COMPUTE SUM(Prod.UnitsInStock * Prod.UnitPrice);
One more time.... Great article.