title: Average on a count() in same query
body: <p>I'm currently working on an assignment which requires me to find the average on the number of resources for each module. The current table looks like this:</p>
  
  <pre><code>ResourceID   ModulID
     1            1
     2            7
     3            2
     4            4
     5            1
     6            1
  </code></pre>
  
  <p>So basically, I'm trying to figure out how to get the average number of resources. The only
  relevant test data here is for module 1, which has 3 different resources connected to it. But I need to display all of the results.</p>
  
  <p>This is my code:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select avg(a.ress) GjSnitt, modulID
  from 
  (select count(ressursID) as ress 
   from ressursertiloppgave
   group by modulID) as a, ressursertiloppgave r
  group by modulID;
  </code></pre>
  
  <p>Obviously it isn't working, but I'm currently at loss on what to change at this point. I would really appreciate any input you guys have.</p>