Want to create o / p as below in Oracle

I need o / p as shown below.

1,1 2,1 2,2 3,1 3,2 3,3 4,1 4,2 4,3 4,4 ... and so on. 

I tried to write a query as shown below. But a throwing mistake. The SIngle row subquery returns more than one row.

 with test1 as( SELECT LEVEL n FROM DUAL CONNECT BY LEVEL <59) select n,( SELECT LEVEL n FROM DUAL CONNECT BY LEVEL <n) from test1 

Appreciate your help in resolving this issue.

+4
source share
1 answer

Here is one way to get the desired result:

 SQL> with t1(col) as( 2 select level 3 from dual 4 connect by level <= 5 5 ) 6 select a.col 7 , b.col 8 from t1 a 9 join t1 b 10 on a.col >= b.col 11 ; COL COL ---------- ---------- 1 1 2 1 2 2 3 1 3 2 3 3 4 1 4 2 4 3 4 4 5 1 5 2 5 3 5 4 5 5 15 rows selected 
+2
source

Source: https://habr.com/ru/post/1447923/


All Articles