0

Recursive query in DB2 to get items in the chain. There is a table

WITH t (id,a) AS (VALUES (1,3),(1,6),(1,9),(2,7),(2,11),(3,5))
SELECT * FROM t

The output should be like this

id   | a
------------
1    | 3,6,9

2    | 7,11

3    | 5

How can I do this using recursive query? Thanks in advance.

Beetee
  • 475
  • 1
  • 7
  • 18
Katerina
  • 1
  • 2
  • Looks LIST_AGG or similar. – jarlh Aug 29 '17 at 14:19
  • as @jarlh suggests above you need to create a string based on each ID using the LIST_AGG function, a resource on this can be found here https://stackoverflow.com/questions/25994896/how-to-convert-column-values-into-separated-with-comma-string-in-db2 – jimmy8ball Aug 29 '17 at 14:30
  • Thanks, Jimmy! I have done this function before but my tutor says do it in another way using recursive query. I am confused. Is there another variant without using lisagg function? – Katerina Aug 30 '17 at 13:17

0 Answers0