ITPub博客

首页 > 数据库 > Oracle > Oracle中自带函数wm_concat排序

Oracle中自带函数wm_concat排序

Oracle 作者:哇哈哈8147 时间:2014-07-07 14:02:10 0 删除 编辑
Oracle 中自带函数wm_concat排序
cuug每周五晚8点都有免费网络课程,可点击cuug官网详细了解。

在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()函数你需要排序!那么在关联前确认他是否已排好序

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29737239/viewspace-1211277/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-04

  • 博文量
    21
  • 访问量
    40457