Here is the recursive query that will complete the task:
WITH RECURSIVE REC_VIEW (COLA, COLB, ROLL_UP, COLC) AS ( SELECT COLA , COLB , MIN(COLC) (VARCHAR(1000)) , MIN(COLC) FROM your_table GROUP BY 1,2 UNION ALL SELECT B.COLA , B.COLB , B.ROLL_UP || ',' || A.COLC , A.COLC FROM your_table A INNER JOIN REC_VIEW B ON A.COLA = B.COLA AND A.COLB = B.COLB AND A.COLC > B.COLC ) SELECT COLA, COLB, ROLL_UP as COLC FROM REC_VIEW QUALIFY ROW_NUMBER() OVER (PARTITION BY COLA, COLB ORDER BY CHARACTER_LENGTH(ROLL_UP) DESC) = 1
I would like to understand how to format the answers better; all my "beautiful" intervals have disappeared. Hope this is clear.
source share