title: MySQL HAVING Clause return empty set?
body: <p>I am having a table below, and I need to write code that extract the rows with budget greater than the average budget. </p>
  
  <pre><code>+------+-----------------+--------+
  | Code | Name            | Budget |
  +------+-----------------+--------+
  |   14 | IT              |  65000 |
  |   37 | Accounting      |  15000 |
  |   59 | Human Resources | 240000 |
  |   77 | Research        |  55000 |
  +------+-----------------+--------+
  </code></pre>
  
  <p>I know this works:</p>
  
  <pre><code>SELECT * FROM Departments WHERE Budget &gt; (SELECT AVG(Budget) FROM Departments);
  </code></pre>
  
  <p>but this looks ugly. <a href="https://stackoverflow.com/questions/2330840/mysql-invalid-use-of-group-function">This post</a> seems to suggest <code>having</code> clause can simplify the query into: </p>
  
  <pre><code>SELECT * FROM Departments HAVING Budget &gt; AVG(Budget);
  </code></pre>
  
  <p>but it returns empty set. Any ideas?</p>
  
  <p>Thanks</p>