In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will introduce in detail for you "mysql how in query operations sort", the content steps are clear and detailed, the details are handled properly, and the editor will update different knowledge points every day, hope that this article "mysql how in query operations sort" can give you unexpected harvest, please follow the editor's ideas slowly in depth, the specific content is as follows, to harvest new knowledge.
In mysql, you can use the "ORDER BY" clause with the SELECT statement in query to operate sorting. The syntax is "select*from table name where field value in (sort 1, sort 2...) order by field (field value, sort 1, sort 2...);".
The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.
Mysql how in query operations are sorted
Let's start with the solution:
Select * from test where id in (3, 1, 5) order by field (id,3,1,5)
Maybe someone will notice.
SQL: select * from table where id IN (3, 6, 9, 1, 2, 5, 8, 7)
After such a situation is taken out, in fact, id is still sorted according to 1, 2, 3, 4, 5, 6, 7, 8, 9.
But what if we really want to sort it in the order in IN? Can SQL finish it?
Do you need to foreach it after you get it back? In fact, mysql has this method.
Field function.
Function format: order by field (str,str1,str2,str3...)
Str is a field, and str1\ str2\ str3 is a specific column value
Sql: select * from table where id IN: order by field (id,3,6,9,1,2,5,8,7); thank you for reading this. I hope you have the most profound understanding of the key question of "how to sort in query operations in mysql" from the practical level, and the specific usage needs to be understood by yourself. if you want to read more related articles, welcome to follow the industry information channel!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.