title: What is the difference of using HAVING vs a subquery
body: <p>I am new to SQL and doing the learning via datacamp. I was wondering if you can achieve the same result with 'HAVING' as with a nested 'WHERE' clause. </p>
  
  <p>Related: <a href="https://stackoverflow.com/questions/9253244/sql-having-vs-where">SQL - having VS where</a> 
  I understand that HAVING is used with aggregate functions such as min, max, ..</p>
  
  <p>How could I rewrite the following with HAVING?:</p>
  
  <pre><code>SELECT *
  FROM populations
  WHERE year = 2015 AND life_expectancy &gt;(
     SELECT AVG(life_expectancy)*1.15
     FROM populations
  );
  </code></pre>
  
  <p>Suppose I have 6 columns in the table 'populations': A (character), B (character), C (Character), D (number, i.e. life_expectancy as in the example), year and E (number). </p>
  
  <p>I tried the following:</p>
  
  <pre><code>SELECT *
  FROM populations
  WHERE year = 2015
  GROUP BY A, B, C, year
  HAVING life_expectancy &gt; AVG(life_expectancy)*1.15; 
  </code></pre>
  
  <p>However, this returns an empty table. I realise it's not a reproducible example, but perhaps a general explanation as to why it might not be working would suffice :) </p>