我有一个带有雇员ID和薪水列的雇员表,但我想对该列进行转置,但不使用pivot
关键字。
原始表
1 10000
2 20000
3 30000
4 40000
5 50000
在选择查询输出后,例如= >>
ID 1 2 3 4 5
------ ----- ----- ----- ----- -----
Salary 10000 20000 30000 40000 50000
答案 0 :(得分:0)
您可以使用条件聚合:
select 'Salary' as id,
max(case when id = 1 then salary end) as salary_1,
max(case when id = 2 then salary end) as salary_2,
max(case when id = 3 then salary end) as salary_3,
max(case when id = 4 then salary end) as salary_4,
max(case when id = 5 then salary end) as salary_5
from t;