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

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;


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


Can use the alias of a column in the ORDER BY clause because it is evaluated after the SELECT clause.