Database MySQL - Transpoing Table from one form to other
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.