如果不使用oralce 11g,那么您需要使用以下解决方案,否则@Dba 回答
WITH t AS
(SELECT 17 wk, 446 COST
FROM DUAL
UNION
SELECT 18 wk, 446 COST
FROM DUAL
UNION
SELECT 19 wk, 446 COST
FROM DUAL
UNION
SELECT 26 wk, 588 COST
FROM DUAL
UNION
SELECT 27 wk, 588 COST
FROM DUAL
UNION
SELECT 28 wk, 588 COST
FROM DUAL)
SELECT COST,
LTRIM
(MAX (SYS_CONNECT_BY_PATH (wk, ','))KEEP (DENSE_RANK LAST ORDER BY curr),
','
) AS COST
FROM (SELECT wk, COST,
ROW_NUMBER () OVER (PARTITION BY COST ORDER BY wk) AS curr,
ROW_NUMBER () OVER (PARTITION BY COST ORDER BY wk)
- 1 AS prev
FROM t)
GROUP BY COST
CONNECT BY prev = PRIOR curr AND COST = PRIOR COST
START WITH curr = 1;