请帮我创建一个MYSQL查询,将列数据用作输出表中的列名:
这是我的表:
ID | Name | Stage ------------------- 1 | John | Stage 1 2 | Mark | Stage 3 3 | Bill | Stage 2 4 | Mary | Stage 2 I want to see this: Stage 1 | Stage 2 | Stage 3 --------------------------- John | Bill | Mark | Mary |
答案 0 :(得分:2)
这是你的mysql查询:
select
case when stage = 'Stage 1' then name end 'Stage 1',
case when stage = 'Stage 2' then name end 'Stage 2',
case when stage = 'Stage 3' then name end 'Stage 3'
from table1;