title: Getting an average from subquery values or another aggregate function in SQL Server
body: <p>I have the SQL statement (SQL Server )</p>
  
  <pre>
  <code>
  SELECT 
  COUNT(ActionName) AS pageCount
  FROM tbl_22_Benchmark
  WHERE DATEPART(dw,CreationDate)&gt;1 AND DATEPART(dw,CreationDate)&lt;7
  GROUP BY 
  dateadd(dd,0, datediff(dd,0,CreationDate))
  </code>
  </pre>
  
  <p>which produces the output</p>
  
  <blockquote>
  <b>pageCount</b><br>
  27<br>
  19<br>
  59<br>
  </blockquote>
  
  <p>Now I would like to get the average of all those figures using SQL. Apparently nested aggregate functions like</p>
  
  <blockquote>
  (AVG(COUNT(pageCount)))
  </blockquote>
  
  <p>are not allowed , and using a subquery like</p>
  
  <pre>
  <code>
  SELECT AVG(pageCount) FROM
  (
  SELECT 
  COUNT(ActionName) AS pageCount
  FROM tbl_22_Benchmark
  WHERE DATEPART(dw,CreationDate)>1 AND DATEPART(dw,CreationDate)&lt;7
  GROUP BY 
  dateadd(dd,0, datediff(dd,0,CreationDate))
  )
  </code>
  </pre>
  
  <p>gets me just an error message <i>Incorrect syntax near ')'.</i> </p>
  
  <p>How can I get the average of the pageCount rows?</p>