title: how to use subtotal in SQL
body: <p>
  I have a table with following data</p>
  
  <pre><code> CODE  NAME   AMOUNT VAT  TOTALAMT FLAG
    10   test1   100    10    110     1
    08   test2    0     0      0      1
    05   test3   10     0      0      2
    03   test4    0     0      0      2
  </code></pre>
  
  <p>
  I want a query which give the following output.
  (Subtotal according to FLAG)</p>
  
  <pre><code> CODE  NAME   AMOUNT VAT  TOTALAMT FLAG
    10   test1   100    10    110      1
    08   test2    0     0      0       1
   NULL SUBTOTAL 100    10    110    NULL
    05   test3   10     0      0       2
    03   test4    0     0      0       2
   NULL SUBTOTAL  10    0     10     NULL
  TOTAL          110    10    120    NULL
  </code></pre>