title: Transform rows into columns dynamically with mysql
body: <p>I have table structure like below</p>
  
  <pre>
  +--------------------------------------+
  ID | cmpgn_pic | cmpgn_dt   | cmpgn_tg |
  +--------------------------------------+
  |1 | NUSNAFIF  | 2015-04-01 | 300000   |
  |2 | PETERBSG  | 2015-04-01 | 30000    |
  |3 | PTYONG    | 2015-04-02 | 700000   |
  |4 | HMKWAN    | 2015-04-01 | 800000   |
  |5 | NUSNAFIF  | 2015-04-05 | 400000   |
  |6 | NUSNAFIF  | 2015-04-02 | 100000   |
  |7 | HMKWAN    | 2015-04-10 | 75000    |
  |9 | PTYONG    | 2015-04-01 | 10000    |
  |10| PTYONG    | 2015-04-05 | 600000   |
  |11| NUSNAFIF  | 2015-04-05 | 600000   |
  |12| HMKWAN    | 2015-04-10 | 800000   |
  +--------------------------------------+
  </pre>
  
  <p>how to write dynamic sql script to get result like below</p>
  
  <pre>
  +---------------------------------------------------------------------------------------------------------------------------------------------+
  | cmpgn_pic | 2015-04-01 | 2015-04-02 | 2015-04-03 | 2015-04-04 | 2015-04-05 | 2015-04-06 | 2015-04-07 | 2015-04-08 | 2015-04-09 | 2015-04-10 |
  +---------------------------------------------------------------------------------------------------------------------------------------------+
  | HMKWAN    | 1          | 0          | 0          | 0          | 0          | 0          | 0          | 0          | 0          | 2          |
  | NUSNAFIF  | 1          | 1          | 0          | 0          | 2          | 0          | 0          | 0          | 0          | 0          |
  | PETEGSG   | 1          | 0          | 0          | 0          | 0          | 0          | 0          | 0          | 0          | 0          |
  | PTYONG    | 1          | 1          | 0          | 0          | 1          | 0          | 0          | 0          | 0          | 0          |
  
  </pre>
  
  <p>I only able to write static mysql script as below</p>
  
  <pre>
  SELECT cmpgn_pic, COUNT(id)
  FROM t_prebook
  group by 1
  </pre>
  
  <p>But I don't know how to display dynamic date into my script. and I look for your help to solve my issue.
  Thanks you in advance.</p>