慕村225694
有很多方法可以进行字符串聚合,但是最简单的方法是用户定义函数。 尝试使用不需要功能的方法。 注意,没有该功能没有简单的方法。这是没有自定义函数的最短路由:(它使用ROW_NUMBER()和SYS_CONNECT_BY_PATH函数)SELECT questionid, LTRIM(MAX(SYS_CONNECT_BY_PATH(elementid,',')) KEEP (DENSE_RANK LAST ORDER BY curr),',') AS elementsFROM (SELECT questionid, elementid, ROW_NUMBER() OVER (PARTITION BY questionid ORDER BY elementid) AS curr, ROW_NUMBER() OVER (PARTITION BY questionid ORDER BY elementid) -1 AS prev FROM emp)GROUP BY questionidCONNECT BY prev = PRIOR curr AND questionid = PRIOR questionidSTART WITH curr = 1;