select * from t where id in (3,1,2)
结果可能是
1, xxx
2, xxx
3, xxx
或者其它,反正不确定
select * from t where id in (3,1,2) order by field(t.id 3, 1, 2)
就可以确定得到这样的排序结果
3, xxx
1, xxx
2, xxx
在ibatis里这样写:
<select id="someSql" parameterClass="list" resultMap="resultMap"> select * from t where id in <iterate open="(" close=")" conjunction=","> #[]# </iterate> order by FIELD(t.id, <iterate conjunction=","> #[]# </iterate> ) </select>