Mysql sorts the output result with the specified ID number

Source: Internet
Author: User

Mysql sorts the output result with the specified ID number

SELECT * FROM 'cms _ hit' WHERE aid in (55,173,177,174,175,176)


Generally, the specified ID of the SQL output needs to be sorted, and the output of the above results has certain uncertainty. According to requirements

55, 6, 5,173,176,174,175,177

.

Sometimes, the results are not only in reverse order, but also in reverse order. At first, I thought it was the rule of finding the ID, but I didn't understand it. I did not make it. I came back and checked the information. It was actually very simple.

SELECT *, instr (', 5,173,176,174,175,177,', concat (',', aid, ',') as c FROM 'cms _ hit' WHERE aid in, 55,173,177,174,175,176) order by c asc

These two functions are also common MYSQL functions.

Instr string 2, and position in string 1.

Concat connection string.

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.