Dear Readers,
I was in a situation, where I needed to get distinct records from group/subgroup partitioned data.
Please note the below sqls can be executed on livesql.oracle.com. This is tested in 19c :)
Query link: https://livesql.oracle.com/apex/livesql/s/ilxt7f2vd91u5tii3eld2brxn
Row source:
Final Query:
I was in a situation, where I needed to get distinct records from group/subgroup partitioned data.
Please note the below sqls can be executed on livesql.oracle.com. This is tested in 19c :)
Query link: https://livesql.oracle.com/apex/livesql/s/ilxt7f2vd91u5tii3eld2brxn
Row source:
select level lvl,mod(level,2) md_lvl2,mod(level,3) md_lvl3
from dual
connect by level < 100
Partitioning:
select md_lvl2
,md_lvl3
,sum(lvl) over (partition by md_lvl2 order by md_lvl3 desc) sumrec
from
(
select level lvl,mod(level,2) md_lvl2,mod(level,3) md_lvl3
from dual
connect by level < 100)
Final Query:
select distinct(md_lvl2||','||md_lvl3||','||sumrec)
from
(
select md_lvl2
,md_lvl3
,sum(lvl) over (partition by md_lvl2 order by md_lvl3 desc) sumrec
from
(
select level lvl,mod(level,2) md_lvl2,mod(level,3) md_lvl3
from dual
connect by level < 100))
order by 1;
Result:
(MD_LVL2||','||MD_LVL3||','||SUMREC) | |||||||||||
0,0,2450 | |||||||||||
0,1,1634 | |||||||||||
0,2,850 | |||||||||||
1,0,2500 | |||||||||||
1,1,1633 | |||||||||||
1,2,800 |