oracle列转行的问题
编号 内容1 内容2
1 aa aa1
1 bb bb1
2 az az1
2 sx sx1
转成
1 aa aa1 bb bb1
2 az az1 sx sx1
------解决方案--------------------WITH TEST AS (
SELECT '1' AS BH,'AA' AS NR1,'AA1' AS NR2 FROM DUAL
UNION
SELECT '1' AS BH,'BB' AS NR1,'BB1' AS NR2 FROM DUAL
UNION
SELECT '2' AS BH,'AZ' AS NR1,'AZ1' AS NR2 FROM DUAL
UNION
SELECT '2' AS BH,'SX' AS NR1,'SX1' AS NR2 FROM DUAL
)
SELECT BH,
MAX(DECODE(ROWNO, 1, NR1, ' ')),
MAX(DECODE(ROWNO, 1, NR2, ' ')),
MAX(DECODE(ROWNO, 2, NR1, ' ')),
MAX(DECODE(ROWNO, 2, NR2, ' '))
FROM (SELECT ROW_NUMBER() OVER(PARTITION BY BH ORDER BY BH) AS ROWNO, BH,NR1,NR2
FROM TEST)
GROUP BY BH
------解决方案--------------------深奥 什么规律? 是固定的字符串和列?
------解决方案--------------------楼主说清楚点,aa aa1 bb bb1一个列的值还是四个列的值?