title: SQL - Does Not Include The Specified Expression as an Aggregate Function
body: <p>I'm attempting to write a query that will calculate and list the student GPA's and then only displays the ones that are below the average GPA of all students. I have successfully gotten the query to output a table with the GPA's of each student, but I can not get it to only display those below the average. </p>
  
  <p>The following is my current query:</p>
  
  <pre><code>    SELECT SC.StudentID, S.StdLastName, GPA
      FROM (SELECT SC.StudentID, S.StdLastName, ROUND(SUM(C.Credits * GV.GradeValue)/SUM(C.Credits), 2) AS GPA
           FROM ((Student_Classes AS SC INNER JOIN GradeValues AS GV ON SC.Grade = GV.Grade) 
           INNER JOIN Students AS S ON SC.StudentID = S.StudentID)
           INNER JOIN Classes as C ON SC.ClassID = C.ClassID
           GROUP BY SC.StudentID, S.StdLastName)
      GROUP BY SC.StudentID, S.StdLastName, GPA
      HAVING GPA &lt; AVG(GPA)
      ORDER BY GPA;
  </code></pre>
  
  <p>When I do this, the error that appears is, </p>
  
  <p>You tried to execute a query that does not include the specified expression GPA &lt; AVG(GPA) as part of an aggregate function.</p>
  
  <p>I have found multiple pages on a similar error on this site, but have still been unable to get it working. Any help would be much appreciated.</p>