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)
上一篇:【CSS-移动端响应式布局详解】


下一篇:联盛德 HLK-W806 (六): I2C驱动SSD1306 128x64 OLED液晶屏