Mysql查询结果顺序按in()中ID的顺序排列的实例分析
程序员文章站
2022-03-21 18:23:02
...
这篇文章主要介绍了详解 Mysql查询结果顺序按 in() 中ID 的顺序排列的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下
详解 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);
以上就是Mysql查询结果顺序按in()中ID的顺序排列的实例分析的详细内容,更多请关注其它相关文章!
上一篇: PHP资源类型实例分享