O'Reilly logo
  • Dustin Waybright thinks this is interesting:

For example, suppose that you need to group only shipped orders by shipper ID and shipping year, and filter only groups having fewer than 100 orders. You can use the following query to achieve this task.

SELECT shipperid, YEAR(shippeddate) AS shippedyear,
   COUNT(*) AS numorders
FROM Sales.Orders
WHERE shippeddate IS NOT NULL
GROUP BY shipperid, YEAR(shippeddate)
HAVING COUNT(*) < 100;


Cover of Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012


This would be applicable to setting min/max sales volume requirements for customers to fall into analyses.