select * from table where id = 1
union
select * from table where id = 37
union
select * from table where id = 7
union
select * from table where id = 9
union
select * from table where id = 26
union
select * from table where id = 12
union
select * from table where id = 156
union
select * from table where id = 18
union
select * from table where id = 24

解决方案 »

  1.   

    in里面有100个id数据。是不是要写100条sql语句,有没有更好的方法呀
      

  2.   

    CREATE  TABLE  SORTID  (
             SORT_ID              NUMBER( 8, 0 )     NOT NULL
          ,  MOTO_ID              NUMBER( 8, 0 )     NOT NULL
          , CONSTRAINT  SORTID_PK  PRIMARY  KEY  (
             SORT_ID )
    )  ;
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(1,1);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(2,37);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(3,7);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(4,9);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(5,26);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(6,12);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(7,156);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(8,18);
    INSERT INTO SORTID(SORT_ID,MOTO_ID) VALUES(9,24);select *
      from table,SORTID
     where table.id in(1,37,7,9,26,12,56,18,24)
       and table.id = SORTID.id
     order by SORTID.SORT_ID;drop table SORTID
      

  3.   

    select 
        *
    from 
        table
    where 
        id in(1,37,7,9,26,12,56,18,24)
    order by 
        DECODE(id,1,1,37,2,7,3,9,4,26,5,12,6,56,7,18,8,24,9);
      

  4.   

    DECODE(id,1,1,37,2,7,3,9,4,26,5,12,6,56,7,18,8,24,9);
    这样的话,学习。