How to sort by specific field value in SQL
It is believed that many inexperienced people don't know what to do about how to sort by a specific field value in SQL. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Id, name
Shandong01 name1
Shandong02 name2
Shandong03 name3
Beijing01 name4
Beijing02 name5
Beijing03 name6
Shanghai01 name7
The copy code is as follows:
Select id,name
From table
Order by case when id like 'shanghai%' then 0 when id like' beijing%' then 1 else 2 end
Result:
Shanghai01 name7
Beijing01 name4
Beijing02 name5
Beijing03 name6
Shandong01 name1
Shandong02 name2
Shandong03 name3
After reading the above, have you mastered the method of sorting by specific field value in SQL? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!