详解 Mysql查询结果顺序按 in() 中ID 的顺序排列
作者:代码也文艺 时间:2024-01-16 06:21:51
详解 Mysql查询结果顺序按 in() 中ID 的顺序排列
实例代码:
<select id="queryGBStyleByIDs" resultMap="styleMap">
select style_num_id ,style_id,style_title,style_pic FROM gb_style where online = 1 AND is_hide = 0 and style_num_id in
<foreach collection="styleNumIDs" item="styleNumId" separator="," open="(" close=")">
#{styleNumId}
</foreach>
ORDER BY FIELD
<foreach collection="styleNumIDs" item="styleNumId" separator="," open="(style_num_id," close=")">
#{styleNumId}
</foreach>
</select>
最终输出sql如下:
select style_num_id ,style_id,style_title,style_pic FROM gb_style where online = 1 AND is_hide = 0 and style_num_id in (1,3,2,5)
order by field (style_num_id,1,3,2,5);
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
来源:http://blog.csdn.net/qq_37107280/article/details/78033724
标签:Mysql,in()
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
使用python装饰器验证配置文件示例
2022-05-27 03:10:11
怎样在SQL Server中去除表中不可见字符
2009-02-05 15:23:00
浅谈Python type的使用
2021-05-17 05:58:59
python实现中文分词FMM算法实例
2022-07-31 18:40:55
vue登录页面回车执行事件@keyup.enter.native问题
2023-07-02 17:01:42
python实现RSA加密(解密)算法
2023-04-20 06:12:15
![](https://img.aspxhome.com/file/2023/8/107088_0s.png)
python简单利用字典破解zip文件口令
2023-06-27 05:36:31
![](https://img.aspxhome.com/file/2023/4/133304_0s.png)
ASP调用数据库常见错误的解决
2007-09-07 10:05:00
python中urlparse模块介绍与使用示例
2021-08-08 10:13:18
vue实际运用之vuex持久化详解
2024-05-09 15:15:50
![](https://img.aspxhome.com/file/2023/2/126512_0s.png)
Go语言ORM框架构造查询条件示例详解
2024-05-05 09:29:30
Python装饰器使用接口测试的步骤
2021-03-27 11:39:06
![](https://img.aspxhome.com/file/2023/9/118429_0s.jpg)
Python中functools模块的常用函数解析
2022-08-12 08:10:50
Vue项目中使用setTimeout存在的潜在问题及解决
2024-05-28 16:00:14
![](https://img.aspxhome.com/file/2023/5/123085_0s.png)
Django配置跨域并开发测试接口
2022-03-20 21:29:08
![](https://img.aspxhome.com/file/2023/2/121162_0s.png)
python字典的setdefault的巧妙用法
2021-05-18 02:58:48
php实现贪吃蛇小游戏
2024-05-02 17:16:36
python实现批量提取指定文件夹下同类型文件
2023-11-17 17:13:31
![](https://img.aspxhome.com/file/2023/4/63934_0s.jpg)
go build失败报方法undefined的解决过程
2023-06-18 15:07:36
![](https://img.aspxhome.com/file/2023/8/87628_0s.png)
python实现机器学习之多元线性回归
2022-09-04 01:42:49
![](https://img.aspxhome.com/file/2023/5/120355_0s.png)