Database MySQL - Transpoing Table from one form to other SET @sql = NULL;
SELECT GROUP_CONCAT(DISTINCT
         CONCAT(
           'MAX(IF(function_NAME = ', function_NAME, 
           ',budget, NULL)) AS ', function_NAME)) 
INTO @sql
FROM country_report dr JOIN function_master am 
    ON dr.function_name = am.func_NAME
 WHERE am.func_CATEGORY = 'FUN';

     SELECT country_location, time_of_day,@sql
               FROM country_report dr 
               WHERE daily_param = 1 
                AND country_location in ('hong kong','tokyo')
              GROUP BY country_location, time_of_day;


output -

| country_location | time_of_day | @sql |
| hong kong        | sod         | MAX(IF(FUNCTION_NAME = Dance program,budget, NULL)) AS Dance program,MAX(IF(FUNCTION_NAME = singing,budget, NULL)) AS singing
| hong kong        | eod         | MAX(IF(FUNCTION_NAME = Dance program,budget, NULL)) AS Dance program,MAX(IF(FUNCTION_NAME = singing,budget, NULL)) AS singing


but required output is 

| country_location | time_of_day | Dance program | singing | 
| hong kong        | sod         | 3             | 4       |
| hong kong        | sod         | 4             | 4       |


Please suggest
Please post question correctly. I am not getting your schema &amp; your second query is showing @sql variable value to same because of last record value in first query stored to @sql due to last write. Post schema of table with some dummy data.

I am trying to understand &amp; conclude that you need column sub-query. I am setting example which could help you.

select (select name from demo where id=outer.id limit 1) as 'subquery-1' , (select age from demo where id=outer.id limit 1) as 'subquery-2' from outer;


Now for your query would be like-

SELECT country_location, time_of_day,
                          (select MAX(IF(FUNCTION_NAME = 'Dance program',budget, NULL) from country_report dr JOIN function_master am ON dr.function_name = am.func_NAME and  WHERE am.func_CATEGORY = 'FUN' and dr.id=outer.id ) as 'Dance Program',
                          (select MAX(IF(FUNCTION_NAME = 'singing',budget, NULL) from country_report dr JOIN function_master am ON dr.function_name = am.func_NAME and  WHERE am.func_CATEGORY = 'FUN' and dr.id=outer.id) as 'Singing'  
       FROM country_report outer 
       WHERE daily_param = 1 AND country_location in ('hong kong','tokyo') 
       GROUP BY country_location, time_of_day;


May be inner subquery return more than 1 record &amp; show error. So please set conditions as your need.