Mysql查詢結果順序按in()中ID的順序排列的案例區分
發表時間:2023-07-19 來源:明輝站整理相關軟件相關文章人氣:
[摘要]這篇文章主要介紹了詳解 Mysql查詢結果順序按 in() 中ID 的順序排列的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下詳解 Mysql查詢結果順序按 in() 中ID 的順序排列實...
這篇文章主要介紹了詳解 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中文網其它相關文章!
學習教程快速掌握從入門到精通的SQL知識。