目前我正在使用pl / sql Developer(Oracle)。我被告知要将行明智的排列数据转换为列,但不使用PIVOT。由于表我正在动态更改,我也无法使用DECODE。
POLICY SEQS INVDATE SUM(AMT)
-------- ------ ----------- ----------
policA 123 01-JAN-10 40
policA 123 01-FEB-10 50
policA 123 01-MAR-10 60
policA 456 01-JAN-10 360
policA 456 01-FEB-10 450
policA 456 01-MAR-10 540
policA 789 01-FEB-10 1000
polcA 789 01-MAR-10 1000
我必须按列重新安排日期和金额总和。因此,单一政策和单个SEQS将在一行中明确列出日期和数量。
"POLICY","SEQS","INST1","INST1SUM","INST2","INST2SUM","INST3","INST3SUM"
"policA","123","01-JAN-10","40","01-FEB-10","50","01-MAR-10","60"
"policA","456","01-JAN-10","360","01-FEB-10","450","01-MAR-10","540"
"policA","789","01-FEB-10","1000","01-MAR-10","1000"
某些政策可能不是从1月开始,因此INST1必须来自feb,INST2必须是Mar和INST3,相应的INSTSUM
必须是NULL
。
有没有办法可以使用CROSS JOINS或使用xml函数来完成? 我可以将xmlagg与替代数据(INST和SUM)一起使用吗?
我做了一些研究,但我无法解决这个问题。你能帮我解决这个问题吗?