mysql 行转列

SET @EE='';
SELECT @EE:=GROUP_CONCAT(@EE,'sum(if(val=\'',val,'\'',',id,0)) as ','''',val,'''') from (select DISTINCT val from hl_test)a;
SET @str=CONCAT('select ',@EE,' from hl_test group by id');
PREPARE stmt from @str;
EXECUTE stmt;

posted @ 2018-12-09 13:56  小九家的丫头  阅读(245)  评论(0编辑  收藏  举报