I would like to brush up one of the basic concept.
We can use SELECT column alias in ORDER BY clause. But we can't use in GROUP BY clause.
The reason is, ORDER BY clause is processed after the SELECT statement; GROUP BY clause is processed before the SELECT statement.
SQL Server Tips · · · ·