title: Oracle PIVOT monthly row data to 12 monthly columns
body: <p>I'm querying a table which has data as such:</p>
  
  <pre><code>ACT  CY  GRP   MONTH     AMT
  111 CY15 AAA 2015-01-01  2.3
  222 CY15 AAA 2015-01-01  3.1 
  111 CY15 AAA 2015-02-01 11.5  
  222 CY15 AAA 2015-02-01 44.6
  111 CY15 AAA 2015-03-01  4.9
  222 CY15 AAA 2015-03-01  3.8
  222 CY15 AAA 2015-04-01    0  
  111 CY15 AAA 2015-04-01 49.8
  111 CY15 AAA 2015-05-01    0 
  222 CY15 AAA 2015-05-01 83.0
  111 CY15 AAA 2015-06-01    0 
  222 CY15 AAA 2015-06-01 79.7
  111 CY15 AAA 2015-07-01 66.4
  222 CY15 AAA 2015-07-01    0 
  222 CY15 AAA 2015-08-01 25.5
  111 CY15 AAA 2015-08-01 63.1
  222 CY15 AAA 2015-09-01 30.4
  111 CY15 AAA 2015-09-01 79.7
  111 CY15 AAA 2015-10-01 28.0
  222 CY15 AAA 2015-10-01 66.4
  222 CY15 AAA 2015-11-01 66.4
  111 CY15 AAA 2015-11-01 28.3
  111 CY15 AAA 2015-12-01 79.7
  222 CY15 AAA 2015-12-01 30.5
  333 CY16 AAA 2016-01-01 25.4
  444 CY16 AAA 2016-01-01 63.1
  444 CY16 AAA 2016-02-01 56.4
  333 CY16 AAA 2016-02-01 20.2
  444 CY16 AAA 2016-03-01 22.4
  333 CY16 AAA 2016-03-01 59.8
  333 CY16 AAA 2016-04-01 58.7
  444 CY16 AAA 2016-04-01 19.5
  333 CY16 AAA 2016-05-01 19.6
  444 CY16 AAA 2016-05-01 58.7
  444 CY16 AAA 2016-06-01 11.7
  333 CY16 AAA 2016-06-01 70.4
  333 CY16 AAA 2016-07-01 58.7
  444 CY16 AAA 2016-07-01 19.5
  444 CY16 AAA 2016-08-01 58.7
  333 CY16 AAA 2016-08-01 19.3
  333 CY16 AAA 2016-09-01 11.3
  444 CY16 AAA 2016-09-01 70.4
  333 CY16 AAA 2016-10-01 55.7
  333 CY16 AAA 2016-11-01 14.3
  333 CY16 AAA 2016-12-01 19.3
  555 CY15 BBB 2015-01-01 58.7
  555 CY15 BBB 2015-02-01 70.4
  555 CY15 BBB 2015-03-01 13.6
  555 CY15 BBB 2015-04-01 55.7
  555 CY15 BBB 2015-05-01 49.8
  555 CY15 BBB 2015-06-01 58.7
  555 CY15 BBB 2015-07-01 65.9
  555 CY15 BBB 2015-08-01 19.0
  555 CY15 BBB 2015-09-01 15.9
  555 CY15 BBB 2015-10-01 87.9
  555 CY15 BBB 2015-11-01 83.5
  555 CY15 BBB 2015-12-01 10.7
  666 CY16 BBB 2016-01-01 87.9
  666 CY16 BBB 2016-02-01 87.9
  666 CY16 BBB 2016-03-01 15.4
  666 CY16 BBB 2016-04-01 83.5
  666 CY16 BBB 2016-05-01 74.7
  666 CY16 BBB 2016-06-01 79.1
  666 CY16 BBB 2016-07-01 47.9
  666 CY16 BBB 2016-08-01 47.9
  666 CY16 BBB 2016-09-01 57.5
  666 CY16 BBB 2016-10-01 47.9
  666 CY16 BBB 2016-11-01 47.9
  666 CY16 BBB 2016-12-01 57.5
  </code></pre>
  
  <p>And I'm trying to display it as follows</p>
  
  <pre><code>GRP CY January February March ... December
  AAA 15   5.4     56.1    AMT  ...    AMT
  AAA 16   AMT     AMT     AMT  ...    AMT
  BBB 15   AMT     AMT     AMT  ...    AMT
  BBB 16   AMT     AMT     AMT  ...    AMT
  </code></pre>
  
  <p>WHERE AMT is the sum of all account amounts for that month in that group and same calendar year.</p>
  
  <p>My first attempt</p>
  
  <pre><code>select * from (select p.grp, p.cy, p.month, p.amt from phasing p WHERE
  p.act IN  ('111', '222', '333', '444', '555', '666') ) pivot( sum(amt) 
  FOR to_char(to_date(month, 'YYYY-DD-MM'), 'Month')
  in 'January', 'February', 'March', 'April')    )
  </code></pre>
  
  <p>ORA-01738: missing IN keyword</p>
  
  <p>This at least didn't error but I don't always know the <code>Month</code> dates</p>
  
  <pre><code>select * from (select p.grp, p.cy, p.month, p.amt from phasing p WHERE
  p.act IN  ('111', '222', '333', '444', '555', '666') ) pivot( sum(amt) 
  FOR month in (to_date('2015-01-01', 'YYYY-MM-DD') As Jan, to_date('2015-02-01', 'YYYY-MM-DD') As Feb)    )
  </code></pre>
  
  <p>I think I need a GROUP BY in my first attempt so that I am not summing all <code>Januarys</code> for every calendar year, but I couldn't even get that to work.  </p>