title: Spark SQL DataFrame HAVING
body: <p>Using pyspark, I have a Spark 2.2 DataFrame <code>df</code> with schema: <code>country: String, year: Integer, x: Float</code>
  I want the average value of <code>x</code> over years for each country, for countries with <code>AVG(x) &gt; 10</code>.
  The following is working:</p>
  
  <pre><code>groups = df.groupBy(df.country).agg(avg('x').alias('avg_x'))
  groups.filter(groups.avg_x &gt; 10)
  </code></pre>
  
  <p>But I am bothered to have to define the useless <code>groups</code> variable. </p>
  
  <p>I have tried:</p>
  
  <pre><code>df.groupBy(df.country).agg(avg('x').alias('avg_x')).filter(df.avg_x &gt; 10)
  </code></pre>
  
  <p>But this results in: <code>AttributeError: 'DataFrame' object has no attribute 'avg_x'</code></p>