我想得到如下表,怎么弄? LocationCode 字段1 字段2 字段3 字段4 字段5 A02b 1 2 3 4 5 A02b 6 7 8 9 10 [最优解释] 搞个建表和查数据额语句出来。那么多数据,懒得给你整 [其他解释] 先3表联合,然后行转列 [其他解释] with TB as ( select a.locationcode,c.codedetail,b.Tallydata from table1 as a inner join table2 as b on a.id=b.detail_id inner join table3 as c on a.locationcode=c.locationcode)
select * from TB pivot(max(Tallydata) for codedetail in ([字段1],[字段2],[字段3],[字段4],[字段5])) as X
[其他解释] with TB as ( select detail_id,a.locationcode,c.codedetail,b.Tallydata from table1 as a inner join table2 as b on a.id=b.detail_id inner join table3 as c on a.locationcode=c.locationcode)
select * from TB pivot(max(Tallydata) for codedetail in ([字段1],[字段2],[字段3],[字段4],[字段5])) as X 加个字段就好了 [其他解释] 变成这样了