Write a query to diplay combinations

 

Expected Output:

[1,2][1,3][1,4][1,5][2,3][2,4][2,5][3,4][3,5][4,5]

 

select level c from dual

connect by level<=5;

1

2

3

4

5

with t as (select level c from dual

connect by level<=5)

select * from t t1 cross join t t2

where t1.c<t2.c;

 

1   2

1   3

1   4

1   5

2   3

2   4

2   5

3   4

3   5

4   5

 

with t as (select level c from dual

connect by level<=5)

select '['||t1.c ||','|| t2.c||']' d from t t1 cross join t t2

where t1.c<t2.c;

[1,2]

[1,3]

[1,4]

[1,5]

[2,3]

[2,4]

[2,5]

[3,4]

[3,5]

[4,5]

with t as (select level c from dual

connect by level<=5)

select listagg(d) within group (order by d)  from (select '['||t1.c ||','|| t2.c||']' d from t t1 cross join t t2

where t1.c<t2.c)

;

[1,2][1,3][1,4][1,5][2,3][2,4][2,5][3,4][3,5][4,5]

No comments:

Post a Comment