Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to sort by specific field value in SQL

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report