Oracle中自带函数wm_concat排序


Oracle 中自带函数wm_concat排序

在wm_concat 连接字符串时发现有时不会按你要求的排序

比如 一个表test有字段 id,name ,product ,num   

 select name ,(select  wm_concat( product'('||tot_num')')

 from ( select  name ,product ,sum(num)  tot_num, row_number()  over (partition by  name order by  sum(num) desc )  as rn

 from  test group by name ,product )  m  where rn<=10  and  m.name=n.name )  px_product

from  test n

group by name

 在子查询排好序在关联 发现 连接的字段就按sum(num)的大小排序了

 

select  name, wm_concat( product'('||tot_num')')  from  (select  name ,product ,sum(num)  tot_num,

 row_number()  over (partition by  name order by  sum(num) desc )  as rn

 from  test group by name ,product

 )  where  rn<=10

group by name

这样就没排序了

感觉在使用wm_concat()函数你需要排序!那么在关联前确认他是否已排好序

相关内容