Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

COUNT(*) KEEP (DENSE_RANK LAST ORDER BY COUNT(*)) OVER (PARTITION BY A,B)

Martin J.Jan 11 2021 — edited Jan 11 2021

Hi,
How do I count(*) over a group that is less aggregated than the group by (in Oracle 12.1)?
Example:
select deptno, lastname, count(*)
, count(*) keep (dense_rank last order by count(*)) over (partition by deptno) ?????
from emp join emp on ...
group by deptno, lastname

I know this works as well:
with x as ( select deptno, lastname, count(*) total from emp join emp on ... group by deptno, lastname)
select y.deptno, y.lastname, y.total, z.total
from x y join (select deptno, sum(total) from x) z on y.deptno = z.deptno

This post has been answered by Martin J. on Jan 11 2021
Jump to Answer
Comments
Post Details
Added on Jan 11 2021
1 comment
1,012 views