title: Alias for GROUP BY clause?
body: <p>In MySQL, it is possible to use an alias in GROUP BY clause that has been created in SELECT clause (Cf. <a href="https://web.archive.org/web/20140902170824/http://dev.mysql.com/doc/refman/5.0/en/group-by-hidden-columns.html" rel="nofollow noreferrer">MySQL Reference</a>).</p>
  <p>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.</p>
  <p>In other words, why is the following ungrammatical?</p>
  <pre><code>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;
  </code></pre>