|
-
The query and its results are given below:
select cod_imm, cod_ritmi, sum(total_area)
from
(select cod_imm, cod_ritmi,
sum(total_area) total_area from TEST4
where cod_ritmi is not null
group by
cod_imm, cod_ritmi
union all
(select c.cod_imm, d.cod_ritmi,
sum(c.total_area) total_area from
TEST4 c,
(select a.cod_imm, a.cod_ritmi
from MAX_TEST1CONTA a
where a.TOTAL_AREA = (select max(b.TOTAL_AREA) from MAX_TEST1CONTA b
where b.cod_imm = a.cod_imm)) d
where c.cod_ritmi is null
and d.cod_imm = c.cod_imm
group by c.cod_imm, d.cod_ritmi))
group by cod_imm, cod_ritmi
COD_IMM COD_RITMI SUM(TOTAL_AREA)
------- ---------- ---------------
2015149 1 9
2015149 4 14
2015149 5 292
2015149 6 416
Is this what you are looking for?
By the way, the data in your earlier post seems to be wrong - the total_area column in the last row of test4 view should read as 27 and not 38.24. Refer the results below:
SQL> select * from test4;
COD_IMM COD_RITMI T TOTAL_AREA
---------- ---------- - ----------
2015149 1 9
2015149 4 14
2015149 5 292
2015149 6 389
2015149 V 27
Cheers!
OraKid.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|