title: MySql query to pull data in matrix form from database
body: <p>I have data in database with two columns name and year. Something like this,</p>
  
  <pre><code>name | year
  -----------
  tim  | 2001
  ron  | 2002
  tim  | 2003
  ron  | 2005
  tim  | 2004
  pol  | 2002
  pol  | 2001
  tim  | 2003
  pol  | 2004
  tim  | 2002
  </code></pre>
  
  <p>I want to output the result matrix something like this. </p>
  
  <pre><code>      tim | pol | ron
  2001   1  |  1  |  0
  2002   1  |  1  |  1
  2003   2  |  0  |  0
  2004   1  |  1  |  0
  2005   0  |  0  |  1
  </code></pre>
  
  <p>tim | pol | ron is arranged in descending order based on cumulative sum i.e tim(5), pol(3), ron(2).</p>
  
  <p>Data is not limited to tim,pol,ron. There can be n-different names.</p>