日期:2014-05-17 浏览次数:21114 次
WITH TT AS
(SELECT 1 ID
FROM DUAL
UNION ALL
SELECT 2 ID
FROM DUAL
UNION ALL
SELECT 3 ID
FROM DUAL
UNION ALL
SELECT 4 ID
FROM DUAL),
T AS
(SELECT 1 ID, 'ZS' NM
FROM DUAL
UNION ALL
SELECT 2 ID, 'ZS' NM
FROM DUAL
UNION ALL
SELECT 2 ID, 'LS' NM
FROM DUAL
UNION ALL
SELECT 3 ID, 'ZS' NM
FROM DUAL
UNION ALL
SELECT 3 ID, 'WW' NM
FROM DUAL)
SELECT TT.ID, T3.NM
FROM TT,
(SELECT T2.ID, ltrim(max(SYS_CONNECT_BY_PATH(t2.NM, '
------解决方案--------------------
')), '
------解决方案--------------------
') NM
FROM (SELECT T.*, ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID) RN
FROM T) T2
connect by prior rn = rn - 1
and prior t2.id = t2.id
GROUP BY T2.ID) T3
WHERE TT.ID = T3.ID(+);