如何按照IN括号内的顺序输出结果

(在SQLserver环境下测试通过)

数值型:
select * from table where id in(1,2,3,4) order by charindex(','+ltrim(rtrim(str(id)))+',',',1,2,3,4,')

字符型:
select * from table where usn in('aaa','bbb','ccc','ddd') order by charindex(usn,'aaa,bbb,ccc,ddd')

你可能感兴趣的:(in)