I have a requirement as- if the user selects checkboxes containing 1,2,3,4 of type 1 and 2,3 of type2 then I should display as (1-4)type1 , (2-3)type2 as the output. We have to do it in backend. I have used LISTAGG
but couldn't achieve the desired output. The user selects the checkbox and we have the values stored in Oracle database. Any inputs will be greatly helpful.
For Ex, the following is my data.
Type | Options |
---|---|
1 | 1 |
1 | 2 |
2 | 2 |
1 | 3 |
2 | 3 |
1 | 4 |
Using LISTAGG I could obtain : select Type , listagg (Option, ',') WITHIN GROUP (ORDER BY Type) selectedOption from ( select .... )
Type | selectedOption |
---|---|
1 | 1,2,3,4 |
2 | 2,3 |
Desired Output:
Type | selectedOption |
---|---|
1 | 1-4 |
2 | 2-3 |