title: Run WHERE over an Average aggregation result - postgresql
body: <p>I have the following query that gets the papers grade listing.</p>
  
  <pre><code>SELECT DISTINCT papers.paper_id, papers.paper_title, AVG(paper_judge_participations.paper_judge_participation_score) AS final_grade,
  (SELECT array_agg(paper_author_name) FROM paper_authors as authors WHERE authors.paper_id=papers.paper_id )::varchar as paper_author_name
  FROM papers 
  FULL JOIN paper_categories ON paper_categories.paper_category_id=papers.paper_category_id
  LEFT JOIN paper_judge_participations ON papers.paper_id = paper_judge_participations.paper_id 
  WHERE ((papers.paper_note IS NULL AND final_grade &gt;= 7) OR (papers.paper_note IS NOT NULL AND papers.paper_note &gt;= 7)) AND papers.paper_category_id = 1
  GROUP BY papers.paper_id ORDER BY final_grade, papers.paper_note;
  </code></pre>
  
  <p>I want to see if the final_grade variable from the the averae result is more than 7 but I get the error:</p>
  
  <pre><code>ERROR:  column "final_grade" does not exist
  LINE 6: WHERE ((papers.paper_note IS NULL AND final_grade &gt;= 7) OR (...
  </code></pre>
  
  <p>How can I use the average result on my <code>WHERE</code> condition?</p>