按照字符串排序的Sql写法

参见下属范例代码:

select * from table1 where id in (3,45,123,54,2) 

order by  charindex(','+cast(id as varchar)+',',',3,45,123,54,2,')
或者也可以是
order by  case when id when 3 then 1 when 45 then 2 when 123 then 3 when 54 then 4 when 2 then 5 end

申明

非源创博文中的内容均收集自网上,若有侵权之处,请及时联络,我会在第一时间内删除.再次说声抱歉!!!

博文欢迎转载,但请给出原文连接。

原文地址:https://www.cnblogs.com/Athrun/p/553685.html