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;
- 5. Grouping and Windowing
- from Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012
- Publisher: Microsoft Press
- Released: December 2012
This would be applicable to setting min/max sales volume requirements for customers to fall into analyses.
Share this highlighthttp://www.safaribooksonline.com/a/training-kit-exam/60177/