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>
acmain, 回的好快啊 ,感激
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 | +------+------+
mysql> select id,name from -> (select *,@n:=@n+1 as k from okdns) z -> order by k desc;简单写 就是直接这样 这样不用建临时表~
+------+------+
| 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>
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 |
+------+------+
-> (select *,@n:=@n+1 as k from okdns) z
-> order by k desc;简单写 就是直接这样 这样不用建临时表~