SET @EE='';
set @str_tmp='';SELECT @EE:=CONCAT(@EE,'GROUP_CONCAT(IF(type=\'',type,'\'',',value,null)) AS ',type,',') as aa into @str_tmp FROM (SELECT DISTINCT type FROM product_category) A order by length(aa) desc limit 1;
SET @QQ=CONCAT('SELECT product_category.product_id,',LEFT(@str_tmp,char_length(@str_tmp)-1),' FROM product_category GROUP BY product_id');
PREPARE stmt FROM @QQ;
EXECUTE stmt;
deallocate prepare stm
t;