详解 Mysql查询结果顺序按 in() 中ID 的顺序排列
吾爱主题
阅读:199
2024-04-05 13:57:52
评论:0
详解 Mysql查询结果顺序按 in() 中ID 的顺序排列
实例代码:
?1 2 3 4 5 6 7 8 9 10 | < 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如下:
?1 2 | 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
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。