title: MySQL Subtotals and Totals in Select query
body: <p>I need <strong>SUBTOTAL</strong> and <strong>GRAN TOTAL</strong> on MySQL table.</p>
  
  <p>For MySQL guide I need use the <strong>WITH ROLLUP</strong> syntax.</p>
  
  <p>I have tried this SQL query without success:</p>
  
  <pre><code>SELECT
      xName,
      xCode,
      sCode,
      FBB88
  FROM
      `doTable`
  GROUP BY
      xCode,
      FBB88 WITH ROLLUP;
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>+-----------+-------+--------+-------+
  | xName     | xCode | sCode  | FBB88 |
  +-----------+-------+--------+-------+
  | AAAAAAAA  | XX4A  | XX4AU1 |     1 |
  | AAAAAAAA  | XX4A  | XX4AU2 |     4 |
  | BBBBBBBBB | XX4B  | XX4BU1 |     2 |
  | BBBBBBBBB | XX4B  | XX4BU2 |     5 |
  +-----------+-------+--------+-------+
  4 rows in set
  </code></pre>
  
  <p>Desired Output:</p>
  
  <pre><code>+-----------+-------+--------+-------+
  | xName     | xCode | sCode  | FBB88 |
  +-----------+-------+--------+-------+
  | AAAAAAAA  | XX4A  | XX4AU1 |     1 |
  | AAAAAAAA  | XX4A  | XX4AU2 |     4 |
  | AAAAAAAA  | XX4A  | SUBTOT |     5 |
  | BBBBBBBBB | XX4B  | XX4BU1 |     2 |
  | BBBBBBBBB | XX4B  | XX4BU2 |     5 |
  | BBBBBBBBB | XX4B  | SUBTOT |     7 |
  |           |       | GRATOT |    12 |
  +-----------+-------+--------+-------+
  </code></pre>