求一个oracle 语句
表 T
TYPE VALUES
A 1
A 2
A 3
B 1
B 2
需要得到的结果
TYPE VALUES
A 1,2,3
B 1,2
请教该怎么写?
------解决方案--------------------SELECT LTRIM(MAX(SYS_CONNECT_BY_PATH(TYPE, ', ')), ', ')
FROM (
SELECT TYPE, VALUES, ROW_NUMBER() OVER (PARTITION BY TYPE ORDER BY VALUES) AS CURR,
ROW_NUMBER() OVER (PARTITION BY TYPE ORDER BY VALUES) - 1 AS PREV
)
START WITH CURR = 1
CONNECT BY CURR = PRIOR PREV AND TYPE = PRIOR TYPE
GROUP BY TYPE