比如查询结果是:id  name
3   xx
9   aa
8   ss
6   rr反转成:id  name
6   rr
8   ss
9   aa
3   xx

解决方案 »

  1.   

    mysql> select * from okdns;
    +------+------+
    | id   | name |
    +------+------+
    |    3 | xx   |
    |    9 | aa   |
    |    8 | ss   |
    |    6 | rr   |
    +------+------+
    4 rows in set (0.05 sec)mysql>
    mysql> select * from okdns
        -> order by find_in_set(id,(select group_concat(id) from okdns)) desc
        -> ;
    +------+------+
    | id   | name |
    +------+------+
    |    6 | rr   |
    |    8 | ss   |
    |    9 | aa   |
    |    3 | xx   |
    +------+------+
    4 rows in set (0.14 sec)mysql>
      

  2.   

    acmain, 回的好快啊 ,感激
      

  3.   

    mysql> set @n=0;
    mysql> create table te select * ,@n:=@n+1 as k from okdns;mysql> select id,name from te order by k desc;
    +------+------+
    | id   | name |
    +------+------+
    |    6 | rs   |
    |    8 | ss   |
    |    9 | aa   |
    |    3 | xx   |
    +------+------+
      

  4.   

    mysql> select id,name from
        -> (select *,@n:=@n+1 as k from okdns) z
        -> order by k desc;简单写 就是直接这样 这样不用建临时表~