1,根据指定id,更新特定字段的值(批量更新)
<update id="updatePageAliasList" parameterType="java.util.List">
UPDATE t_web_page_alias set url_name = CASE id
<foreach collection="list" index="index" item="item">
WHEN #{item.id} THEN #{item.urlName}
</foreach>
END,
url_desc = CASE id
<foreach collection="list" index="index" item="item">
WHEN #{item.id} THEN #{item.urlDesc}
</foreach>
END
WHERE id IN
<foreach collection="list" index="index" item="item" open="(" close=")" separator=",">
#{item.id}
</foreach>
</update>SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4,5,6,7,8,9,排序的,但如果我们真要按IN里面的顺序排序怎么办?SQL能不能完成?是否需要取回来后再foreach一下?其实mysql就有这个方法
select * from test where id in(3,1,5) order by find_in_set(id,'3,1,5');
本文介绍如何使用MySQL的find_in_set()函数实现自定义ID排序,适用于需要按特定顺序获取记录的场景。通过案例演示了当ID顺序不同时,如何利用此函数确保查询结果符合预期顺序。
1586

被折叠的 条评论
为什么被折叠?



