title: How to convert row to column in MySQL
body: <p>I am trying to dynamically convert rows to columns in MySQL.</p>
  <p>Table name is student_det.</p>
  <pre><code>ID    Roll_No         Q.No
  1      21345         100
  2      21345         102
  3      21345         103
  4      21346         100
  5      21346         144
  6      21567         233
  7      21567         455
  
  **Ans should be like** 
  
      Roll_no Qno1    Qno2    Qno3
      21345   100      102    103
      21346   100      144    null
      21567   233      455    null
    ----------    
  </code></pre>
  <p>The code I use to convert rows to columns, is the following</p>
  <pre><code>Select roll_no,Q.No1, Q.No2,Q.No3
  From
  (
    Select Roll_No, Q.No,
      'Q.No'+
        CAST(row_number() over(partition by Roll_No order by Roll_No) 
       as varchar(10)) ColumnSequence
    from student_det
  ) as Temp
  PIVOT
  (
    MIN(Q.No)
    FOR ColumnSequence IN(Q.No1, Q.No2,Q.No3)
  ) as Piv
  </code></pre>