我正在尝试在 SQL Server 中获取相关矩阵,并且我的数据以下列方式在表中:
RptLOB1 RptLOB2 Correlation
AE AE 1
Bail AE 0.35
Commercial Bail 0.25
Commercial AE 0.15
...等等。
我想编写一个代码,所以我的输出如下所示:
AE Bail Commercial
AE 1 0.35 0.15
Bail 0.35 1 0.25
Commercial 0.15 0.25 1
RptLOB 的顺序无关紧要,只要从上到下和从左到右的顺序相同即可。我一直在试图找到一种方法来解决这个问题,但我不太确定最好的方法是什么。我在考虑使用 PIVOT,但这不会在顶部输出 RptLOB(它们将被视为表中的列)。
编辑:
此输出将被插入到另一个表中,如下所示:
col1 col2 col3 col4 col5
Generic
Company Inputs Insurance Stochastic Model Correlations Exposure Correlation Matrix
AE Bail Commercial
AE 1 0.35 0.15
Bail 0.35 1 0.25
Commercial 0.15 0.25 1