mysql模拟rownum的一个方法
mysql> select * from t2; +----+---------------------+ | id | d | +----+---------------------+ | 1 | 2015-08-02 15:13:59 | | 3 | 2015-08-05 16:56:23 | | 4 | 2015-08-05 16:56:24 | | 6 | 2015-08-05 16:56:26 | | 7 | 2015-08-05 16:56:28 | | 8 | 2015-08-05 16:56:29 | +----+---------------------+ 6 rows in set (0.00 sec) mysql> set @x=0; Query OK, 0 rows affected (0.00 sec) mysql> select @x:=ifnull(@x,0)+1 as rownum,d as time from t2; +--------+---------------------+ | rownum | time | +--------+---------------------+ | 1 | 2015-08-02 15:13:59 | | 2 | 2015-08-05 16:56:23 | | 3 | 2015-08-05 16:56:24 | | 4 | 2015-08-05 16:56:26 | | 5 | 2015-08-05 16:56:28 | | 6 | 2015-08-05 16:56:29 | +--------+---------------------+ 6 rows in set (0.00 sec)