Good article...
One comment though...
I would not filter on a row value in a having statement, the code is wasting CPU cycles and too much memory swapping.
The last example would be an illustration of that.
SELECT StoreName
,SUM(TotalSalesAmount) AS StoreSalesAmount
FROM dbo.SalesTransaction
GROUP BY StoreName
HAVING StoreName LIKE '%Outlet%' <==== NOT GOOD
OR StoreName LIKE '%Books%';
This should be better written like:
SELECT StoreName
,SUM(TotalSalesAmount) AS StoreSalesAmount
FROM dbo.SalesTransaction
WHERE StoreName LIKE '%Outlet%' <=== This way the row is not even loaded in to memory to be aggregated.
OR StoreName LIKE '%Books%';
GROUP BY StoreName