title: Select rows with subtotals maintaining proper order
body: <p>I am trying to get the output of my query as below please help me</p>
  
  <pre><code>partno    value     value1    phaseid
  ABCD      10        11        A
  ABCD      11        12        B
  Subtotal  21        23    
  DEFG      20        21        C
  Subtotal  20        21
  IJKL      30        31        A
  IJKL      31        32        D
  Subtotal  61        63
  
  
  CREATE TABLE test_table
  (
    partno text,
    value bigint,
    value1 bigint,
    phaseid text
  )
  
  INSERT INTO test_table(
              partno, value, value1, phaseid)
      VALUES ('ABCD', 10, 11, 'A'),('ABCD', 11, 12, 'B'),('DEFG', 20, 21, 'C'),('IJKL', 30, 31, 'A'),
      ('IJKL', 31, 321, 'D');
  </code></pre>
  
  <p>Below is the Query i am using</p>
  
  <pre><code>Select a.partno,a.value,a.value1,b.phaseid
  from (
  select partno,value,value1 from test_table a
  Union all
  Select 'Subtotal',Sum(value),sum(value1) from test_table a
  Group By partno
  ) as a
  Left Join test_table b USING (partno)
  order by  value,value1
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/03JD0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/03JD0.png" alt="enter image description here"></a></p>