Home >Database >Mysql Tutorial >Oracle中自带函数wm_concat排序

Oracle中自带函数wm_concat排序

WBOY
WBOYOriginal
2016-06-07 17:26:172831browse

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

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

group by name

这样就没排序了

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

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn