SELECT country, YEAR(hiredate) AS yearhired, COUNT(*) AS numemployees FROM HR.Employees WHERE hiredate >= '20030101' GROUP BY country, YEAR(hiredate) HAVING COUNT(*) > 1 ORDER BY country , yearhired DESC;
- 1. Foundations of Querying
- from Training Kit (Exam 70-461): Querying Microsoft® SQL Server® 2012
- Publisher: Microsoft Press
- Released: December 2012
Can use the alias of a column in the ORDER BY clause because it is evaluated after the SELECT clause.
Share this highlighthttp://www.safaribooksonline.com/a/training-kit-exam/56342/