title: MySQL 5.6 move rows into columns (pivot function)
body: <p>We have the following input:</p>
  
  <pre><code>ID,MONTH,AMOUNT
  1,1,1.1
  1,2,2.1
  1,3,3.1
  </code></pre>
  
  <p>We would like to output it as:</p>
  
  <pre><code>ID,AMOUNT_JAN,AMOUNT_FEB,AMOUNT_MAR
  1,1.1,2.1,3.1
  </code></pre>
  
  <p>So far the query we got:</p>
  
  <pre><code>SELECT ID,
  CASE WHEN MONTH = '1' THEN AMOUNT END AS AMOUNT_JAN,
  CASE WHEN MONTH = '2' THEN AMOUNT END AS AMOUNT_FEB,
  CASE WHEN MONTH = '3' THEN AMOUNT END AS AMOUNT_MAR
  FROM TEST2
  </code></pre>
  
  <p>Can only generate outputs like the following:</p>
  
  <pre><code>ID,AMOUNT_JAN,AMOUNT_FEB,AMOUNT_MAR
  1,1.1,NULL,NULL
  1,NULL,2.1,NULL
  1,NULL,NULL,3.1
  </code></pre>
  
  <p>Could any guru enlighten?</p>
  
  <p>The SQL Fiddle is available here for your convenience:</p>
  
  <p><a href="http://sqlfiddle.com/#!9/017d9c/3" rel="nofollow">http://sqlfiddle.com/#!9/017d9c/3</a></p>