您的位置:首页 > 数据库

在t-sql 中使查詢結果按照自定義的字串排序

2009-02-23 12:01 232 查看
-- sql server

select id

from

(

select '1' as id union all

select '2' union all

select '3' union all

select '4' union all

select '5'

) t

order by case when charindex(id, '3, 2, 4, 1') = 0 then 1000000 else charindex(id, '3, 2, 4, 1') end

-- oracle

select id

from

(

select '1' as id from dual union all

select '2' from dual union all

select '3' from dual union all

select '4' from dual union all

select '5' from dual

) t

order by case when instr('3, 2, 4, 1', id) = 0 then 1000000 else instr('3, 2, 4, 1', id) end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: