首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

怎么保持where in查询后的顺序

2012-10-16 
如何保持where in查询后的顺序参数数组aint[] a [2848,2846,2845,2844,2847,2818]select Id from StateI

如何保持where in查询后的顺序
参数数组a
int[] a =[2848,2846,2845,2844,2847,2818];

select Id from StateInfo where Id in(2848,2846,2845,2844,2847,2818) ;

结果按从小到大排列了: 2818,2844,2845,2846,2847,2848;
如何保持查询结果仍按参数a里的次序呢?

[解决办法]
select Id from StateInfo where Id in(2848,2846,2845,2844,2847,2818) order by instr('2848,2846,2845,2844,2847,2818',id)

热点排行