我有张表 
ID  NAME 
1    aa 
2    bb 
3    cc 
4    dd 
5    ee 
6    ff 我要按2,4,6,7的顺序进行显示

解决方案 »

  1.   

    select *
    from tb
    order by case id when 2 then 0 when 4 then 1 when 6 then 3 when 7 then 4 else id+4 end
      

  2.   

    select *
    from yourTable
    order by INSTR(',2,4,6,7,',cancat(',',id,','));
      

  3.   

    出错 1305-FUNCTION aaa.cancat does not exits
      

  4.   

    select *
    from yourTable
    order by INSTR(',2,4,6,7,',concat(',',id,','));
      

  5.   

    create table tb(id int,name varchar(20));
    insert tb 
    select 1,    'aa'  union all 
    select 2,    'bb'  union all 
    select 3,    'cc'  union all 
    select 4,    'dd'  union all 
    select 5,    'ee'  union all 
    select 6,    'ff'select * from tbselect *
    from tb
    order by case id when 2 then 0 when 4 then 1 when 6 then 3 when 7 then 4 else id+4 end/**result:
    "2" "bb"
    "4" "dd"
    "6" "ff"
    "1" "aa"
    "3" "cc"
    "5" "ee"
    **/
      

  6.   

    try:
    select *
    from tb
    order by if(id=2,1,if(id=4,2,if(id=6,3,if(id=7,4,id))))
      

  7.   

    try: 
    select * 
    from tb 
    order by if(id=2,1,if(id=4,2,if(id=6,3,if(id=7,4,id+10))))ORDER BY的速度慢,不如建立一个临时表,字段ID、排序顺序,与工作表连接,再按排序顺序 排序即可