order by case when name='a' then 1 when name='c' then 2 when name='b' then 3 else 4 end

解决方案 »

  1.   

    如果不加order by,默认是按聚集索引排序,如果没有聚集索引,应该是按插入顺序排序的。
    如果想按特殊要求进行排序,只能用order by。
    按你说的,则是:order by case when name = 'a' then 1 when name = 'c' then 2 when name = 'b' then 3 else 9 end
    如果要“按照where条件的先后顺序”排序,那只有在拼SQL语句时,拼order by语句。
      

  2.   

    select  * from table where name in('a','c' ,'b') order by charindex(name,'a,c,b')传参数时只需要这样传'a,c,b',在语句里拼以上语句