select username from unserinfo where username in ('A3','b4','a2','A1') order by charindex(username,'A3,b4',a2,A1')
order by charindex(username,'A3,b4','a2',A1')
order by charindex(username,'A3','b4','a2','A1')
order by (case when username ='A3' then 1 when username ='B4' then 2 when username ='a2' then 3 else 4 end)
完全不靠谱,看看MSDN的说明 CHARINDEX Returns the starting position of the specified expression in a character string. Syntax CHARINDEX ( expression1 , expression2 [ , start_location ] )
select username from unserinfo where username in ('A3','b4','a2','A1') order by charindex(','+username+',',',A3,b4,a2,A1,')
select username from unserinfo where username in ('A3','b4','a2','A1) order by (case when username ='A3' then 1 when username ='B4' then 2 when username ='a2' then 3 else 4 end)
username from unserinfo where username in ('A3','b4','a2','A1') order by (case when username ='A3' then 1 when username ='B4' then 2 when username ='a2' then 3 else 4 end)
这个比较弱智,但肯定满足你的要求:select username from unserinfo where username ='A3' union select username from unserinfo where username ='b4' union select username from unserinfo where username ='a2' union select username from unserinfo where username ='A1'
order by case when end
正解!select username from unserinfo where username in ('A3','b4','a2','A1') order by charindex(username,'A3,b4,a2,A1')还是谢谢各位了!
order by charindex(username,'A3,b4',a2,A1')
when username ='B4' then 2
when username ='a2' then 3
else 4 end)
完全不靠谱,看看MSDN的说明
CHARINDEX
Returns the starting position of the specified expression in a character string. Syntax
CHARINDEX ( expression1 , expression2 [ , start_location ] )
order by charindex(','+username+',',',A3,b4,a2,A1,')
order by (case when username ='A3' then 1
when username ='B4' then 2
when username ='a2' then 3
else 4 end)
order by (case when username ='A3' then 1
when username ='B4' then 2
when username ='a2' then 3
else 4 end)
union
select username from unserinfo where username ='b4'
union
select username from unserinfo where username ='a2'
union
select username from unserinfo where username ='A1'
case when
end
order by charindex(username,'A3,b4,a2,A1')还是谢谢各位了!