我正在尝试将多个数据透视合并为一个语句。请您帮助我如何合并。
SELECT ID, A as [LglCode-A],B as [LglCode-B],C as [LglCode-C],D as [LglCode-D] from
(
select ID,LglFlg, Code
from #tmp1
) x
pivot
(
max(Legal)
for Code in ([A],[B],[C],[D])
) p;
SELECT ID, A as [MH Code-A],B as [MH Code-B],C as [MH Code-C],D as [MH Code-D] from
(
select ID,[MH Code], Code
from #tmp1
) x
pivot
(
max([MH Code])
for Code in ([A],[B],[C],[D])
) p;
我从链接中看到了这种方法,这是唯一更好的方法吗?ms sql多次透视另一个表
2条答案
按热度按时间wrrgggsh1#
我建议条件聚合。我想这正是你想要的:
tcbh2hod2#
您可以尝试以下操作:
由于这里没有可用的测试数据,您可能需要在这里或那里进行一些更改。