SQL查询语句如下:
select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44)我想让结果按10,32,22,76,13,44的顺序检索出来,但是检索后的顺序变成了按ID排序的:10,13,22,32,44,76。请问如何让结果不排序呢???多谢!

解决方案 »

  1.   

    一个变通的方法select *,
    case id 
    when 10 then 1 
    when 32 then 2 
    when 22 then 3 
    when 76 then 4 
    when 13 then 5 
    when 44 then 6 
    END as seq
    from table 
    where (ID = 10) 
    or (ID = 32) 
    or (ID = 22) 
    or (ID = 76) 
    or (ID = 13) 
    or (ID = 44)
    order by seq
    == 思想重于技巧 ==
      

  2.   


    select * from table where ID in(10,32,22,76,13,44); 
      

  3.   


    不行的,一样是顺序排的,我试过了.你可以这样
    (select * from table where ID = 10) union (select * from table where ID = 32) union (select * from table where ID = 22) union (select * from table where ID = 76) union (select * from table where ID = 13) union (select * from table where ID = 44) 
      

  4.   

    简单点的。select * from (select * from table where ID in(10,32,22,76,13,44)) T order by rand();
      

  5.   

    select *,
    INSTR(',10,32,22,76,13,44,', ','+id+',') as seq
    from table 
    where id in(10,32,22,76,13,44)
    order by seq
    == 思想重于技巧 ==
      

  6.   


    不错,这样也可以
    select *
    from table 
    where id in(10,32,22,76,13,44)
    order by instr(',10,32,22,76,13,44,', ','+id+',') 
      

  7.   

    那是ID吧?默认排序.
    你可以order by random()
      

  8.   

    select * from table where (ID = 10) or (ID = 32) or (ID = 22) or (ID = 76) or (ID = 13) or (ID = 44) 
    OEDER BY 列名[ASG] -- 升序
    好象可以这样用,没试过!!!
      

  9.   

    哈哈哈哈哈哈哈,你们都不行,看我的。
    select *
    from table 
    where id in(10,32,22,76,13,44)
    order by field (id,10,32,22,76,13,44);
      

  10.   

    select a.*, a. from 
    (
    select table.id, 600 as  from table where table.id=10 union 
    select table.id, 500 as  from table where table.id=32 union 
    select table.id, 400 as  from table where table.id=22 union 
    select table.id, 300 as  from table where table.id=76 union 
    select table.id, 200 as  from table where table.id=13 union 
    select table.id, 100 as  from table where table.id=44 
    ) as a order by  desc;
      

  11.   

    select * 
    from table  
    where id in(10,32,22,76,13,44) 
    order by field (id,10,32,22,76,13,44); 
    我试过了,可是里面说field无法识别的函数,怎么办啊?
      

  12.   

    怎么可能,你的table 没有id字段吧?要不就是你用的不是MySQL