我正在寻找这样的查询:
id | int | 自动增量 varchar | 255
insert into `table` set something = concat('val', id);
这样桌子就看起来像
1 | val1 2 | val2 3 | val3 …
除了id总是val0以每一行都结束而已。
val0
我怎样才能做到这一点?
mysql> describe concattest; +-------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+------------------+------+-----+---------+----------------+ | id | int(10) unsigned | NO | PRI | NULL | auto_increment | | val | text | YES | | NULL | | +-------+------------------+------+-----+---------+----------------+ 2 rows in set (0.00 sec) mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID())); Query OK, 1 row affected (0.06 sec) mysql> select * from concattest; +----+------+ | id | val | +----+------+ | 1 | val0 | +----+------+ 1 row in set (0.00 sec) mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID())); Query OK, 1 row affected (0.00 sec) mysql> select * from concattest; +----+------+ | id | val | +----+------+ | 1 | val0 | | 2 | val1 | +----+------+ 2 rows in set (0.00 sec) mysql> INSERT INTO concattest (val) VALUES (concat('val', LAST_INSERT_ID())); Query OK, 1 row affected (0.00 sec) mysql> select * from concattest; +----+------+ | id | val | +----+------+ | 1 | val0 | | 2 | val1 | | 3 | val2 | +----+------+ 3 rows in set (0.00 sec)