日期:2014-05-16 浏览次数:20979 次
set @floor := 0; select @floor := @floor + 1 as '编号', comment.* from comment
mysql> SELECT * FROM TA4;
+------+
| ID |
+------+
| 102 |
| 203 |
| 213 |
| 222 |
| 258 |
| 288 |
| 298 |
| 322 |
+------+
8 rows in set (0.00 sec)
mysql> SET @NUM:= 0;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT * FROM (
-> SELECT *,@NUM:= @NUM + 1 AS '编号' FROM TA4) A ORDER BY 编号 LIMIT 3,3;
+------+------+
| ID | 编号 |
+------+------+
| 222 | 4 |
| 258 | 5 |
| 288 | 6 |
+------+------+
3 rows in set (0.00 sec)
mysql>
------解决方案--------------------
set @floor := 0; select * from (select @floor := @floor + 1 as `编号`, comment.* from comment) t where `编号`>=4 limit 3;