In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to sort Mysql order by according to the list of specified values". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to sort Mysql order by according to the list of specified values.
The sort statement order by of Mysql is no stranger to you. Order by column asc/desc can basically meet the needs of daily development according to the ascending or descending order of the data in the table.
But sometimes special needs will be encountered, such as sorting by order status, according to outstanding payment-paid-to-ship-delivered. Sort the order data in order, etc. At this time, you can define the status of the order as the number 1, 2, 2, 3, 4. When querying, it can be solved in ascending order.
If the customer requires that the order to be paid is arranged in the ascending order according to the submission time, and the other status order is arranged in the descending order according to the submission time, at this time, the order status 1meme 2jin3jin4 is not easy to use, of course, generally we will not really define the order status as 1meme 2jin3jin4 but will define the dictionary data, such as unpay,unsend and so on, to form the order status, which will be clear to other developers at a glance.
To solve the above problems, we can adopt the following solutions:
Select * from xxx order by case when "order_stauts" = "unpay" then 1 else 2 end asc, create_time asc if other states also need sorting: select * from xxx order by case when "order_stauts" = "unpay" then 1 when "order_stauts" = "unsend" then 2 else 3 end asc, create_time asc so far, I believe you have a deeper understanding of "Mysql order by how to sort according to the specified value list", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.