这篇文章主要介绍了详解 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的顺序排列的实例分析的详细内容。