困难是动摇者和懦夫掉队回头的便桥;但也是勇敢者前进的脚踏石。我不识何谓君子,但看每事肯吃亏者便是;我不识何谓小人,但看每事好占便宜者便是。
详解 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的顺序排列。最初的梦想,最初两个字,其实已暗暗说明,这是一个不可能的梦想,一个悲涩的故事。更多关于详解Mysql查询结果顺序按in()中ID的顺序排列请关注haodaima.com其它相关文章!