当前位置:网站首页>Mysql把查询到的结果集按指定顺寻进行排序
Mysql把查询到的结果集按指定顺寻进行排序
2022-07-29 05:06:00 【nianyuw】
在开发过程中可能会遇到,如何想把查询到的结果集按指定顺序进行排序,就可以使用FIELD函数
- FIELD(str,str1,str2,str3):
其中str是字段名称,可以对SQL查询的结果集按照指定顺序排序,字段str按str1,str2,str3的顺序返回查询到的结果集
案例:查询的结果将推送状态(0:正常 1:优推 2:下架)按优推,正常,下架排序,状态如果相同按更新时间降序
select 查询的数据 from 查询的表 where 查询的条件 order by FIELD(push_status,1,0,2)
在mybatisPlus中可以使用
queryWrapper.last("order by FIELD(push_status,1,0,2");
举例:
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)
上面两个sql语句都进行了拍寻,一个是默认升序,一个使用了FIELD函数
结果如下图
第一个sql
第二个sql
边栏推荐
- 深度学习刷SOTA的一堆trick
- How does word view document modification traces? How word views document modification traces
- JS daily question (11)
- Flink+Iceberg环境搭建及生产问题处理
- Create a mindscore environment in modelars, install mindvision, and conduct in-depth learning and training (Huawei)
- WPS如何进行快速截屏?WPS快速截屏的方法
- Flink+iceberg environment construction and production problem handling
- Five correlation analysis, one of the most important skills of data analysts
- Office提示系统配置无法运行怎么办?
- 【文件下载】Easyexcel快速上手
猜你喜欢

荣耀2023内推,内推码ambubk

Learn matlab to draw geographical map, line scatter bubble density map

How to set row height and column width in excel? The method of setting row height and column width in Excel

Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function

How is the entered query SQL statement executed?

pytorch学习笔记

Pivot table of odoo development tutorial

The person who goes to and from work on time and never wants to work overtime has been promoted in front of me

Sparksql inserts or updates in batches and saves data to MySQL

如何安装office2010安装包?office2010安装包安装到电脑上的方法
随机推荐
On prepayment of house purchase
Original code, inverse code, complement code
Huawei ilearning AI mathematics foundation course notes
Pytorch learning notes
Climbing the pit of traffic flow prediction (III): using pytorch to realize LSTM to predict traffic flow
开区网站打开自动播放音乐的添加跟修改教程
如何让照片中的人物笑起来?HMS Core视频编辑服务一键微笑功能,让人物笑容更自然
[2022 freshmen learning] key points of the third week
WPS insert hyperlink cannot be opened. What should I do if I prompt "unable to open the specified file"!
Excel卡住了没保存怎么办?Excel还没保存但是卡住了的解决方法
IDEA中使用注解Test
What servers are needed to build mobile app
Using jupyter (I), install jupyter under windows, open the browser, and modify the default opening address
Operator operation list of spark
Improve the readability of your regular expressions a hundred times
Conv1d of torch
新产品上市最全推广方案
那个准时上下班,从不愿意加班加点的人,在我前面升职了...
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】
Google gtest事件机制