56,940
社区成员




set @floor := 0; select @floor := @floor + 1 as '编号', comment.* from comment
mysql> show warnings;
+---------+------+-----------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------+
| Warning | 1292 | Truncated incorrect DOUBLE value: '? ?' |
+---------+------+-----------------------------------------+
1 row in set (0.08 sec)
mysql> set @num:=0; select floor from (select floor, @num:=@num+1 as '编号' from comment order by floor) a order by '编号' limit 2,3;
Query OK, 0 rows affected (0.00 sec)
+-------+
| floor |
+-------+
| 102 |
| 203 |
| 213 |
+-------+
3 rows in set (0.00 sec)
set @num:=0; select * from (SELECT *, @num:= @num + 1 AS '编号' FROM comment) t where '编号'>4 limit 3;
Query OK, 0 rows affected (0.00 sec)
Empty set, 1 warning (0.00 sec)
mysql> set @num:=0; select * from (select *, @num:=@num+1 as '编号' from comment) a where '编 号'>4 order by '编号' limit 3;
Query OK, 0 rows affected (0.00 sec)
Empty set, 1 warning (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
-> WHERE 编号>=4 ORDER BY 编号 LIMIT 3;
+------+------+
| ID | 编号 |
+------+------+
| 222 | 4 |
| 258 | 5 |
| 288 | 6 |
+------+------+
3 rows in set (0.00 sec)
mysql>
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>
----增加id
alter table comment add column id int auto_increment not null;
--到编号4和其后面的2行
select * from comment order by id limit 4,2;