当前位置:网站首页>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
边栏推荐
- Legend how to configure multiple versions of wechat updates on one server
- IOS interview preparation - Online
- 玩家访问网站自动弹窗加QQ群方法以及详细代码
- Learn matlab to draw geographical map, line scatter bubble density map
- Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- 开源汇智创未来 | 2022开放原子全球开源峰会 openEuler 分论坛圆满召开
- Spark的算子操作列表
- DataSourceClosedException: dataSource already closed at Mon Oct 25 16:55:48 CST 2021
- JS daily question (10)
猜你喜欢
How to solve the problem of configuring the progress every time Office2010 is opened?
Climbing the pit of traffic flow prediction (II): the simplest LSTM predicts traffic flow using tensorflow2
Using jupyter (I), install jupyter under windows, open the browser, and modify the default opening address
Create a mindscore environment in modelars, install mindvision, and conduct in-depth learning and training (Huawei)
Unity Metaverse(三)、Protobuf & Socket 实现多人在线
怎样监测微型的网站服务
虚拟偶像的歌声原来是这样生成的!
Un7.28: common commands of redis client.
输入的查询SQL语句,是如何执行的?
荣耀2023内推,内推码ambubk
随机推荐
Activity workflow table structure learning
Improve the readability of your regular expressions a hundred times
Numpy basic learning
AttributeError: ‘module‘ object has no attribute ‘create_ connection‘
深度学习刷SOTA的一堆trick
AttributeError: ‘module‘ object has no attribute ‘create_connection‘
电脑无法打开excel表格怎么办?excel打不开的解决方法
Climbing the pit of traffic flow prediction (III): using pytorch to realize LSTM to predict traffic flow
[wechat applet -- solve the alignment problem of the last line of display:flex. (discontinuous arrangement will be divided into two sides)]
【无标题】
Data Lake: spark, a distributed open source processing engine
What if the computer cannot open excel? The solution of Excel not opening
Word如何查看文档修改痕迹?Word查看文档修改痕迹的方法
How to monitor micro web services
Flink+Iceberg环境搭建及生产问题处理
Office提示系统配置无法运行怎么办?
Mapper agent development
玩家访问网站自动弹窗加QQ群方法以及详细代码
P1009 [noip1998 popularization group] sum of factorials
如何安装office2010安装包?office2010安装包安装到电脑上的方法