您好,欢迎来到年旅网。
搜索
您的当前位置:首页Oracle中自带函数wm_concat排序

Oracle中自带函数wm_concat排序

来源:年旅网

Oracle 中自带函数wm_concat排序 在wm_concat 连接字符串时发现有时不会按你要求的排序 比如 一个表test有字段 id,name ,product

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

linux

Copyright © 2019- oldu.cn 版权所有 浙ICP备2024123271号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务