In MySQL, it is possible to use an alias in GROUP BY clause that has been created in SELECT clause (Cf. MySQL Reference).
I am just wondering why it is not possible to create an alias in GROUP BY and use it in SELECT, which follows the execution order of SELECT statement.
In other words, why is the following ungrammatical?
SELECT region, SUM(population)
FROM population_us_states
GROUP BY
CASE state_name
WHEN 'CT' THEN 'New England'
WHEN 'RI' THEN 'New England'
WHEN 'MA' THEN 'New England'
WHEN 'ME' THEN 'New England'
WHEN 'NH' THEN 'New England'
WHEN 'VT' THEN 'New England'
WHEN 'CA' THEN 'West Coast'
WHEN 'OR' THEN 'West Coast'
WHEN 'WA' THEN 'West Coast'
ELSE 'other' END AS region;