取出分组之后每组前10条数据 oracle

时间:2021-01-24 15:10:24
--取出x || '_' || y 分组之后每组前10条数据
 select * from (
       select  x,y,sj,ddbz,
            row_number() over (partition by x || '_' || y order by sj desc) rn   
             from test 
         where  x is not null  and y is not null      

) where rn <= 10 


--行转列数据

select x|| '_' || y jdwd, wm_concat(distinct DDBZ) from(
 select * from (
       select  x,y,sj,ddbz,
            row_number() over (partition by x || '_' || y order by sj desc) rn   
             from qb_gissj 
         where  x is not null  and y is not null      
) where rn <= 10) 
group by (x || '_' || y)