我的表格结构如下:
Person_id Add_Type Address
1 Present A
1 Permanent B
我想要数据透视表如下:
Person_id Present Permanent
1 A B
答案 0 :(得分:1)
首先尝试使用任何搜索引擎......这就是你需要的:
示例数据
create table #t
(
Person_id VARCHAR(MAX),
Add_Type VARCHAR(MAX),
Address_ VARCHAR(MAX)
)
insert into #t values ('1','Present', 'A'), ('1','Permanent', 'B')
<强> QUERY 强>
select *
from (select Person_id, Add_Type, Address_
from #t
)as src
pivot
(
min(Address_)
for Add_Type in ([Present], [Permanent])
) as pvt
<强>输出强>
Person_id Present Permanent
1 A B