in语句查询按in里的顺序返回记录 博客分类: 数据库mysql
程序员文章站
2024-03-22 20:35:16
...
<select id="qryQuestionListByQuestionIds" resultType="com.xxx.model.entity.ExamQuestion"> select * from T_EXAM_QUESTION where ORG_ID = #{orgId} and ID in <foreach collection="questionIdList" index="index" item="item" open="(" separator="," close=")"> #{item} </foreach> order by field(ID, <foreach collection="questionIdList" index="index" item="item" separator=","> #{item} </foreach> ) </select>
返回结果会按in里的顺序返回。