title: Total Count in Grouped TSQL Query
body: <p>I have an performance heavy query, that filters out many unwanted records based on data in other tables etc.</p>
  
  <p>I am averaging a column, and also returning the count for each average group.  This is all working fine.</p>
  
  <p>However, I would also like to include the percentage of the TOTAL count.</p>
  
  <p>Is there any way of getting this total count without rerunning the whole query, or increasing the performance load significantly?  </p>
  
  <p>I would also prefer if I didn't need to completely restructure the sub query (e.g. by getting the total count outside of it), but can do if necessary.</p>
  
  <pre><code>SELECT 
      data.EquipmentId,
      AVG(MeasureValue) AS AverageValue,
      COUNT(data.*) AS BinCount
      COUNT(data.*)/ ???TotalCount??? AS BinCountPercentage
  FROM
  (SELECT * FROM MultipleTablesWithJoins) data
  GROUP BY data.EquipmentId
  </code></pre>