title: Why ORDER BY works only when I gave an alias name for the column, but didn't work just as column name?
body: <p>This code cannot be executed, showed an error like</p>
  <blockquote>
  <p>column &quot;o.total_amt_usd&quot; must appear in the GROUP BY clause or be used in an aggregate function</p>
  </blockquote>
  <pre><code>SELECT a.name, MIN(o.total_amt_usd) 
  FROM accounts a
  JOIN orders o ON a.id = o.account_id
  GROUP BY a.name
  ORDER BY o.total_amt_usd 
  LIMIT 3
  </code></pre>
  <p>But after I use an alias, it worked:</p>
  <pre><code>SELECT a.name, MIN(o.total_amt_usd) small
  FROM accounts a
  JOIN orders o ON a.id = o.account_id
  GROUP BY a.name
  ORDER BY small 
  LIMIT 3
  </code></pre>
  <p>Could anybody explain a little bit about this, please?</p>
  <p>Both logically make sense to me. But one of them is not working.</p>
  <p>Thanks a lot.</p>