当前位置: 移动技术网 > IT编程>数据库>Mysql > 详解 Mysql查询结果顺序按 in() 中ID 的顺序排列

详解 Mysql查询结果顺序按 in() 中ID 的顺序排列

2017年12月07日  | 移动技术网IT编程  | 我要评论

安师大空乘,无赖总裁的前妻,甘肃移动网上营业厅缴费

详解 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);

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网