I want to print those combination which have exact 110 sum.
Here I give some data for an example.
10
20
30
60
40
70
99
90
80
And output is
80,20,10
70,30,10
SQL> create table t ( x int );
Table created.
SQL> insert into t values (10);
1 row created.
SQL> insert into t values (20);
1 row created.
SQL> insert into t values (30);
1 row created.
SQL> insert into t values (60);
1 row created.
SQL> insert into t values (40);
1 row created.
SQL> insert into t values (70);
1 row created.
SQL> insert into t values (99);
1 row created.
SQL> insert into t values (90);
1 row created.
SQL> insert into t values (80);
1 row created.
SQL>
SQL> with tt (elem, tot , str) as
2 ( select x elem, x tot , to_char(x) str
3 from t
4 union all
5 select x, tot+x, str||','||x
6 from tt, t
7 where t.x > tt.elem
8 )
9 select str from tt
10 where tot = 110;
STR
------------------------------
20,90
30,80
40,70
10,20,80
10,30,70
10,40,60
20,30,60
7 rows selected.