title: The "right" way to calculate subtotals using SQL
body: <p>I have a table that looks like this</p>
  
  <pre><code>Person#  |  Person Name   | Gender | Persons Net Worth
  -----------------------------------------------------------
  1          Donald J           M        20
  2          George W           M        20
  3          Mark   B           T        20
  4          Hil    C           F        20
  5          Hil    C           F        20
  6          Bill   C           M        20
  7          Eric   Z           M        20
  8          Caitl  J           T        20
  </code></pre>
  
  <p>I want to gather subtotals for each <em>gender</em> group. I need to essentially </p>
  
  <p>incorporate a <code>sum(NETWORTH) where gender = 'M' group by gender sort by gender</code></p>
  
  <p>and a </p>
  
  <p><code>sum(NETWORTH) where gender = 'F' group by gender sort by gender</code> </p>
  
  <p>and a </p>
  
  <p><code>sum(NETWORTH) where gender = 'T' group by gender sort by gender</code></p>
  
  <p>So I basically want the result to be this:</p>
  
  <pre><code>Person#  |  Person Name   | Gender | Persons Net Worth
  -----------------------------------------------------------
  1          Donald J           M        20
  2          George W           M        20
  6          Bill   C           M        20
  7          Eric   Z           M        20
                                  Total: 80
  4          Hil    C           F        20
  5          Hil    C           F        20
                                  Total: 40
  3          Mark   B           T        20
  8          Caitl  J           T        20
                                  Total: 40
  </code></pre>
  
  <p>I tried using <code>WITH ROLLUP</code> but ended up failing miserably. I know how to manipulate in the code behind to achieve this but I'd rather do it all in one SQL Query if possible. </p>
  
  <p>Thanks in advance</p>