Sorting with the built-in function wm_concat in Oracle

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.