当前位置: 代码迷 >> Oracle开发 >> oracle 语句
  详细解决方案

oracle 语句

热度:102   发布时间:2016-04-24 07:53:42.0
求一个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
  相关解决方案