mysql 动态横向扩展



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;

阅读更多
上一篇MYSQL 锁
下一篇mysql 动态列转行
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭