id    name   num
1      aa     3
2      bb     0
3      cc     0
4      dd     1
5      ee     2
6      ff     5
查询条件 3,1,4如 select id,name from 表 where id in(3,1,4)如何排序才能使果结为下面这样
id    name   num
3      cc     0
1      aa     3
4      dd     1如何将这个结果合并成  cc,aa,dd

解决方案 »

  1.   

    没办法
    只能select * from tb where id=3
    union all
    select * from tb where id=1
    union all
    select * from tb where id=4
      

  2.   

    select id,name from 表 where id in(3,1,4) order by find_in_set('3,1,4');
      

  3.   


    这个真是学习了!不过测试需要如下语法才通过:select id,name from 表 where id in(3,1,4) order by find_in_set(id, '3,1,4');
      

  4.   


    如果数据是下面这样的,排序就不对了id name num
    104  aa   105
    105  bb   106
    106  cc   0查询后正确的排序应该是下面这样的
    id name num
    104 cc   0
    105 bb   106
    106 aa   105查询的条件 106,105,104
      

  5.   

    上面的打错了查询后正确的排序应该是下面这样的
    id name num
    106 cc  0
    105 bb  106
    104 aa  105查询的条件 106,105,104