title: mysql group_concat output as the another query column list
body: <p>I want to generate a cross tab query in MySQL. I used <code>group_concat</code>, but it is not working. I issued the following query to generate the year list:</p>
  
  <pre><code>set @v1 = (SELECT GROUP_CONCAT(DISTINCT 
  CONCAT('\\nsum(CASE WHEN myear=\"', myear ,'\" 
  THEN amount ELSE NULL END) AS\"', myear,'\"')) AS column_list
  FROM mdata
  where myear &gt; 1972 and myear &lt; 1974);
  select myear, amount, @v1 from mdata;
  </code></pre>
  
  <p>It produced the list of years in <code>@v1</code> but with binary field. I want to use it in my next query to make the cross tab query.</p>
  
  <p>I can run the first query with PHP and store the value in a variable and use it in the next query, but how it can be done in MySQL?</p>