Sorting with the built-in function wm_concat in Oracle
When wm_concat is connected to the string, it is found that sometimes it is not sorted according to your requirements.
For example, a table named test has the field id, name, product, and 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
Sort the join fields in the subquery order by 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
So there is no sorting.
It feels like you need to sort using the wm_concat () function! Check whether the order is sorted before Association.