Get the App
SLTechnology News&Howtos  ›  Database  › 

How to sort by specific field value in SQL

Shulou Source: shulou.com Published: 2022-05-31 20:48:44 11月13日 Update

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!

Tags: Fields sorting code content methods more problems helpless for this reason skills articles experience industry information information channels channels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi macOS Docker OPPO Reno Shulou Tech Info