title: Percentage from Total SUM after GROUP BY SQL Server
body: <p>I have these results:</p>
  
  <pre><code>PersonID    SUM(PA.Total)
  -------------------------
     1            75
     2            75
     3            15
     4            15
     5            60
     6            60
  </code></pre>
  
  <p>With the table like:</p>
  
  <pre><code>PersonID    Total
  ------------------
     1         50
     2         50
     3         10
     4         10
     5         40
     6         40
     1         25
     2         25
     3          5
     4          5
     5         20
     6         20
  </code></pre>
  
  <p>These are grouped by the person. Now I'm looking to add a column with the percentages for each person calculated from the total of all of their sums.</p>
  
  <p>For example: the total sum is 300, and hence I need a result like this:</p>
  
  <pre><code>PersonID    SUM(PA.Total)   Percentage
  --------------------------------------
     1            75              25%
     2            75              25%
     3            15              5%
     4            15              5%
     5            60              20%
     6            60              20%
  </code></pre>
  
  <p>I have looked at code online and I have come up with a fix such as this:</p>
  
  <pre><code> SELECT 
       P.PersonID, SUM(PA.Total)
       SUM(PA.Total) * 100 / [p] AS 'Percentage'
   FROM 
       Person P
   JOIN 
       Package PA ON P.PersonID = PA.PackageFK
   CROSS JOIN 
       (SELECT SUM(PA.[Total]) AS [p] 
        FROM Package PA) t
   GROUP BY 
       P.PersonID
  </code></pre>
  
  <p>But I'm unsure how to incorporate the cross join into the join as well as the already group/sum section. Or whether this is along the right lines altogether.</p>
  
  <p>Any help would be appreciated - SQL fiddle <a href="http://sqlfiddle.com/#!9/80f91/2" rel="noreferrer">http://sqlfiddle.com/#!9/80f91/2</a></p>