I have a table like below -
COL1 COL2
-------------
101 A
102 B
102 C
102 D
103 C
103 E
I need to generate all possible combinations along with uniqueID for a set of unique values in COL1
shown as below - For example - There are 3 unique values in COL1
, 6 combinations are possible and so 18 rows should be in the result. There can be "n" number of unique values. I need a dynamic solution that should work with any number of combinations and values
1,101,A
1,102,B
1,103,C
2,101,A
2,102,B
2,103,E
3,101,A
3,102,C
3,103,C
4,101,A
4,102,C
4,103,E
5,101,A
5,102,D
5,103,C
6,101,A
6,102,D
6,103,E
Please help and suggest an answer. I tried using LAG,LEAD, CROSS JOIN, unable to get to a solution.
Answer can be using any of HANA SQL Script or Oracle SQL or MS-SQL.