欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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里的顺序返回。