I have a table of two columns
Col1 Col2
A 1
A 2
A 3
B 1
B 2
B 3
Output I need is like this
Col1 Col2
A 1
A 1,2
A 1,2,3
B 1
B 1,2
B 1,2,3
Thank you in advance.
Here is a solution which would work for MySQL. It uses a correlated subquery in the select clause to group concatenate together
Col2
values. The logic is that we only aggregate values which are less than or equal to the current row, for a given group of records sharing the sameCol1
value.Demo
Here is the same query in Oracle:
Demo
Note that the only real change is substituting
LISTAGG
forGROUP_CONCAT
.