title: SQL Having aggregate function?
body: <p>I have table with students and evaluations. It is necessary to return the number of repetitions all ratings but without MIN and MAX number of repetitions grade.</p>
  
  <p>When I'am runnig this query:</p>
  
  <pre><code>SELECT 
       [Grade],
       COUNT([Grade]) AS [Number of repetitions]
       FROM [Test].[dbo].[Evaluation]
       GROUP BY Grade 
  </code></pre>
  
  <p>I have this result and it is ok, but how to show this query withuout MIN and MAX Number of repetitions.(In that case 6 - 120 and 10 - 4)</p>
  
  <pre><code>Grade    Number of repetitions
   6              120
   7              35
   8              93
   9              25
  10              4 
  </code></pre>
  
  <p>I tried wtih HAVING on this way, but it does not work. This is message in SQL: "Cannot perform an aggregate function on an expression containing an aggregate or a subquery"</p>
  
  <pre><code>SELECT 
       [Grade],
       COUNT([Grade]) AS [Number of repetitions]
       FROM [Test].[dbo].[Evaluation]
       GROUP BY Grade 
       HAVING COUNT([Grade) &gt; (SELECT MIN(COUNT([Grade])) FROM [Test][dbo].[Evaluation] GROUP BY Grade) 
       AND 
       HAVING COUNT([Grade) &lt; (SELECT MAX(COUNT([Grade])) FROM [Test][dbo].[Evaluation] GROUP BY Grade)
  </code></pre>
  
  <p>Thank you very much.</p>