select name_new,
max(case when name = 'PersonA' then A end) as PersonA,
max(case when name = 'PersonB' then A end) as PersonB,
max(case when name = 'PersonC' then A end) as PersonC
from
(select name, 'A1' name_new, A1 A from mytable union all
select name, 'A2' name_new, A2 A from mytable union all
select name, 'A3' name_new, A3 A from mytable union all
select name, 'A4' name_new, A4 A from mytable ) t
group by name_new
1条答案
按热度按时间yh2wf1be1#
可以使用条件聚合和
union all
具体如下:sqlfiddle公司