在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
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
相关文章推荐
- 在t-sql 中使查詢結果按照自定義的字串排序
- 让sql语句不排序,按照in语句的顺序返回结果
- sql语句-按照汉字拼音首字母排序
- SQL 语句中按照in语句原有的顺序进行排序
- SQL截取一个字段中不确定字母和数字并按照数字顺序排序
- SQL 从一个sql 语句结果中(作为AS一个表) 查询结果 ;按照count排序
- sql中文字段按照汉语拼音首字母排序
- SQL 按照汉字拼音排序
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果
- sql order by+字段,指定按照哪个字段来排序
- sql按照特定的字段排序
- sql按照in排序
- 在sql中不指定Order by排序是按照主键吗
- 在sql中不指定Order by排序是按照主键吗
- sql语句 不让结果排序,按照in语句的顺序返回结果
- sql cookbook 2.3 按字串排序问题
- 部分随笔(SQL按照特定顺序排序、按照拼音排序)
- 让sql语句不排序,按照in语句的顺序返回结果
- 让sql语句不排序,按照in语句的顺序返回结果