查询使用列数据作为列名
Query to use column data as column name
请帮我创建一个 MYSQL 查询以在输出中使用列数据作为列名 table:
这是我的 table:
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 |
这是您的 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;
请帮我创建一个 MYSQL 查询以在输出中使用列数据作为列名 table:
这是我的 table:
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 |
这是您的 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;