当前位置:网站首页>MySQL sorts the queried result set according to the specified sequence
MySQL sorts the queried result set according to the specified sequence
2022-07-29 05:10:00 【nianyuw】
During the development process, you may encounter , How to sort the queried result set in the specified order , You can use FIELD function
- FIELD(str,str1,str2,str3):
among str Is the field name , It can be done to SQL The result set of the query Sort in the specified order , Field str Press str1,str2,str3 Returns the query result set in the order of
Case study : The result of the query will be pushed to the status (0: normal 1: Youtui 2: Off the shelf ) Push by priority , normal , Off shelf sorting , If the status is the same, it will be updated in descending order
select Query data from The query table where Query criteria order by FIELD(push_status,1,0,2)
stay mybatisPlus Can be used in
queryWrapper.last("order by FIELD(push_status,1,0,2");
give an example :
SELECT t_enterprise.name,t_enterprise.audit_status FROM t_enterprise WHERE delete_flag = 0 order by audit_status
SELECT t_enterprise.name,t_enterprise.audit_status FROM t_enterprise WHERE delete_flag = 0 order by FIELD(audit_status,1,0,2)
The top two sql Sentences are patted , One is the default ascending order , One is used FIELD function
The results are as follows
first sql
the second sql
边栏推荐
- Mysql语句中的函数
- js(forEach)出现return无法结束函数的解决方法
- Understand activity workflow
- Mysql多对多关系,分组拼接把多个数据查询到一条数据上
- The most comprehensive promotion plan for the launch of new products
- Mysql把查询到的结果集按指定顺寻进行排序
- 力扣------对奇偶下标分别排序
- How to install Office2010 installation package? How to install Office2010 installation package on computer
- Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
- Apache POI实现Excel导入读取数据和写入数据并导出
猜你喜欢

excel怎么设置行高和列宽?excel设置行高和列宽的方法

How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally

输入的查询SQL语句,是如何执行的?

Office提示系统配置无法运行怎么办?

Solution | get the relevant information about the current employees' highest salary in each department |

如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然

The most comprehensive promotion plan for the launch of new products

TCP三次握手四次挥手

开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开

How to install Office2010 installation package? How to install Office2010 installation package on computer
随机推荐
开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开
excel怎么设置行高和列宽?excel设置行高和列宽的方法
Google GTEST event mechanism
Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
网安学习-内网安全1
Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
JS daily question (10)
五个关联分析,领略数据分析师一大重要必会处理技能
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
Learn the first program of database
Create a mindscore environment in modelars, install mindvision, and conduct in-depth learning and training (Huawei)
IDEA中使用注解Test
向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!
Raspberry pie 4B + Intel neural computing stick (stick2) +yolov5 feasibility study report
传奇服务端如何添加地图
ODOO开发教程之透视表
Unity Metaverse(三)、Protobuf & Socket 实现多人在线
Rolabelimg to data format data
How to set row height and column width in excel? The method of setting row height and column width in Excel
Solution | get the relevant information about the current employees' highest salary in each department |