我一直试图摆脱使用DECODE在Oracle 11g中透视行的问题,在Oracle 11g中有方便的PIVOT函数。但我可能发现了一个局限性:
我正在尝试为基表中的每个值返回2列。就像是:
SELECT somethingId, splitId1, splitName1, splitId2, splitName2 FROM (SELECT somethingId, splitId FROM SOMETHING JOIN SPLIT ON ... ) PIVOT ( MAX(splitId) FOR displayOrder IN (1 AS splitId1, 2 AS splitId2), MAX(splitName) FOR displayOrder IN (1 AS splitName1, 2 as splitName2) )
我可以使用DECODE做到这一点,但是我无法通过语法来让我使用PIVOT做到这一点。这有可能吗?似乎该函数处理起来并不难。
编辑:是不是StackOverflow可能不是SQL问题的正确溢出?
编辑:有人在那里吗?
从oracle-developer.net看来,它可以像这样完成:
SELECT somethingId, splitId1, splitName1, splitId2, splitName2 FROM (SELECT somethingId, splitId FROM SOMETHING JOIN SPLIT ON ... ) PIVOT ( MAX(splitId) , MAX(splitName) FOR displayOrder IN (1 AS splitName1, 2 as splitName2) )