分别查表table1,条件分别为id in ('2');id in ('1');id in ('3'),然后union关联

解决方案 »

  1.   

    select * from table1 where id in('1','2','3')
    order by case when id='2' then 1 else 2 end
      

  2.   

    select * from table1 order by   
    charindex(','+id+',',',2,1,3,') asc
      

  3.   

    zlp321002(飘过)
    你那个不行,还是一样的结果
      

  4.   

    --测试环境
    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 行)
      

  5.   

    zlp321002的方法很不错啊!只是你需要在他的思路上改一改,按你的思路使用吧!
      

  6.   

    zlp321002(飘过)我试了还是不行啊,我们把问题普通话,如果我数据库里有一万个记录,我现在查到十个数据必须按照规定的顺序,该顺序和数据库里的顺序不同,我该怎么弄?难道循环十次查找?
      

  7.   

    如果指定了 SELECT DISTINCT,那么 ORDER BY 子句中的项就必须出现在选择列表中