使用分析函数后如何将行放在一起

How to get rows together after using analytic function

create table xyz ( contrno number , mobile number primary key); 

insert into xyz values(1003288127,123456); 
insert into xyz values(1003288127,123457); 
insert into xyz values(1003288127,123458); 
insert into xyz values(1003288127,123459); 
insert into xyz values(1003288127,123450); 
insert into xyz values(1003288127,123451); 
insert into xyz values(1003288127,123452); 
insert into xyz values(1003288127,123453); 
insert into xyz values(1003288127,123454); 
insert into xyz values(1003288127,123455); 

我希望行应该按 contrno 计数的降序排列,并且所有 contrno 行应该在一起,这意味着 rownum 应该是连续的, 我写了这个查询

select c.* 
from xyz c 
order by count(c.contrno) over ( partition by c.contrno ) desc) t 

根据正确的 contrno 计数排列行,但并非所有 contrno 都放在一起

但是当我通过以下查询查询 rownum 时

select k.* from (select rownum rn ,t.* from(select c.* 
from xyz c 
order by count(c.contrno) over ( partition by c.contrno ) desc) t ) k 
where k.contrno=1003288127 

输出为

rn contrno 
1 51024 1003288127 
2 51025 1003288127 
3 51089 1003288127 
4 51090 1003288127 
5 51091 1003288127 
6 51092 1003288127 
7 51093 1003288127 
8 51094 1003288127 
9 51095 1003288127 
10 51096 1003288127 
11 51097 1003288127 

所以在这里,如果您在 51024 和 51025 之后看到,51089 正在开始,而在 51025 和 51089 之间,其他 contrno 即将到来。

请回答发生这种情况的原因以及如何编写可以根据顺序 rownum 提供输出的查询

如果我没理解错的话,你想先按计数再按 contrno 订购:

order by count(c.contrno) over ( partition by c.contrno ) desc, c.contrno

甚至还可以通过手机

order by count(c.contrno) over ( partition by c.contrno ) desc, c.contrno,  c.mobile