title: Multiple counts on different tables in same query
body: <p>We have a tool that allows users to create their own groups. Within these groups, users can write posts. What I am trying to determine is the relationship between size of the group and total number of posts in that group.</p>
  
  <p>I can do SQL statements to get a list of group names and the number of users in that group (Query 1) and a list of group names and the number of posts (Query 2) but I would like for both to be in the same query.</p>
  
  <p>Query 1</p>
  
  <pre><code>select count(pg.personID) as GroupSize, g.GroupName
  from Group g inner join PersonGroup pg g.GroupID = pg.GroupID
  where LastViewed between @startDate and @enddate and
      g.Type = 0
  group by g.GroupID, g.GroupName
  order by GroupSize
  </code></pre>
  
  <p>Query 2</p>
  
  <pre><code>select count(gp.PostID) as TotalPosts, g.GroupName
  from Group g inner join GroupPost gp on g.GroupID = gp.GroupID
      inner join Post p on gp.PostID = p.PostID
  where g.Type = 0 and
      gp.Created between @startDate and @enddate
  group by g.GroupID, g.GroupName
  order by TotalPosts
  </code></pre>
  
  <p>**Note: A person can post the same "post" to multiple groups</p>
  
  <p>I believe from this data I could build a Histogram (# of groups with 10-20 users, 21-30 users, etc..) and incorporate average number of posts for groups in those different bins. </p>