您的位置:首页 > 数据库

按照字符串排序的Sql写法

2006-11-08 08:27 232 查看
参见下属范例代码:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: