title: Sum total Sales and Buys at same record group by month?
body: <p>I have a table which is like this.</p>
  
  <pre><code>id date       subtotal type
  1 |2017-12-12 | 50.00 | 1
  2 |2017-12-12 | 20.00 | 2
  3 |2017-11-12 | 30.00 | 2
  4 |2017-11-12 | 40.00 | 1
  5 |2017-10-12 | 70.00 | 1
  6 |2017-10-12 | 250.00| 2
  </code></pre>
  
  <p>In that case the type column presents sales (1) and buys(2). What I want to do is, group by this orders by month and get the total sale and buys at this month. Something like this.</p>
  
  <pre><code>id date        sale     buy
  1 |December   | 50.00 | 20.00
  2 |November   | 30.00 | 40.00
  3 |October    | 70.00 | 250.00
  </code></pre>
  
  <p>When I try something like this,</p>
  
  <pre><code> select to_char(date,'Mon') as Month,
         extract(year from date) as Year,
         case when type= 1 then sum("subtotal")  END as sales,
         case when type= 2 then sum("subtotal")  END as buys
     from table
     group by 1,2,type
  </code></pre>
  
  <p>result does not look like what I want. The months will appear at different columns. Like this.</p>
  
  <pre><code>month year    sales buys
  Oct   |2017|  70.00 | 0
  Oct   |2017|  0     | 250.00
  </code></pre>
  
  <p>How can I accomplish this? I just want to monthly sum records.</p>