Quantcast
Viewing latest article 13
Browse Latest Browse All 13

Re: Help with request

Cydia wrote:

ArtNick;
It is necessary maximum at lines from 2 tables. I.e. for example in the first table 10 of lines, in the second 15, as a result should it turns out 15

with t as (
select 1 id, ' PETROV ' fio, 51 acc, 550 nSum from dual
union all
select 1 id, ' PETROV ' fio, 61 acc, 560 nSum from dual
union all
select 1 id, ' IVANOV ' fio, 21 acc, 250 nSum from dual
union all
select 1 id, ' IVANOV ' fio, 25 acc, 350 nSum from dual
);
t2 as (
select 1 id, ' IVANOV ' fio, 23 acc, 150 nSum from dual
union all
select 1 id, ' IVANOV ' fio, 30 acc, 130 nSum from dual
union all
select 1 id, ' IVANOV ' fio, 29 acc, 50 nSum from dual
union all
select 1 id, ' PETROV ' fio, 66 acc, 566 nSum from dual
union all
select 1 id, ' Stax ' fio, 66 acc, 566 nSum from dual
)
select nvl (x.fio, y.fio), x.acc acc_x, x.nsum nsum_x, y.acc acc_y, y.nsum nsum_y from
(select t. *, row_number () over (partition by fio order by 1) n from t) x
==> FULL OUTER JOIN
(select t2. *, row_number () over (partition by fio order by 1) n from t2) y
on (x.n=y.n and x.fio=y.fio)
order by 1
/
SQL> /
NVL X. ACC_X NSUM_X ACC_Y NSUM_Y
------ ---------- ---------- ---------- ----------
IVANOV 21 250 23 150
IVANOV 25 350 30 130
IVANOV 29 50
PETROV 51 550 66 566
PETROV 61 560
Stax 66 566
6 rows selected.

.....
stax


Viewing latest article 13
Browse Latest Browse All 13

Trending Articles