第 1 条附言 · 2018-06-01 15:08:25 +08:00
已解决
drop table tb;
create TEMPORARY table tb(tpname varchar(10),`level` int,`name` varchar(10));
insert into tb
VALUES('tp1',1,'a'),('tp1',2,'b'),('tp1',3,'c'),('tp2',1,'d'),('tp2',2,'e');
select tpname,GROUP_CONCAT(level1) as aa,GROUP_CONCAT(level2) as bb,GROUP_CONCAT(level3) as cc from (
select tpname,
case when `level`=1 then name end as level1,
case when `level`=2 then name end as level2,
case when `level`=3 then name end as level3
from tb a
) as dd
GROUP BY tpname