This is how I resolved my issue, that might help.
WITH RECURSIVE base (c_rnk, c_list)
AS
(
SELECT
rnk c_rnk,
CAST(TRIM(columnname) AS VARCHAR(5000)) c_list
FROM MYDB.MYTB
WHERE rnk = 1
UNION ALL
SELECT
rnk c_rnk,
b.c_list || ',' || CAST(TRIM(c.columnname) AS VARCHAR(5000)) c_list
FROM MYDB.MYTB c
INNER JOIN base b
ON b.c_rnk + 1 = c.rnk
)
SELECT c_list FROM base
QUALIFY RANK() OVER (ORDER BY c_rnk DESC) = 1
;
↧