select * from table1 where id in('1','2','3') order by case when id='2' then 1 else 2 end
select * from table1 order by charindex(','+id+',',',2,1,3,') asc
zlp321002(飘过) 你那个不行,还是一样的结果
--测试环境 declare @t table(id varchar(10)) insert into @t select 1 union all select 2 union all select 3 --第一种方式 select * from @t order by charindex(','+id+',',',1,2,3,') asc --第二种方式 select * from @t order by charindex(','+id+',',',2,1,3,') asc--结果(所影响的行数为 3 行)id ---------- 1 2 3(所影响的行数为 3 行)id ---------- 2 1 3(所影响的行数为 3 行)
order by case when id='2' then 1 else 2 end
charindex(','+id+',',',2,1,3,') asc
你那个不行,还是一样的结果
declare @t table(id varchar(10))
insert into @t select 1
union all select 2
union all select 3
--第一种方式
select * from @t
order by charindex(','+id+',',',1,2,3,') asc
--第二种方式
select * from @t
order by charindex(','+id+',',',2,1,3,') asc--结果(所影响的行数为 3 行)id
----------
1
2
3(所影响的行数为 3 行)id
----------
2
1
3(所影响的行数为 3 行)