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 stmt;


阅读更多
文章标签: mysql 扩展
个人分类: 数据库
想对作者说点什么? 我来说一句

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

不良信息举报

mysql 动态列转行

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭