gpt4 book ai didi

mysql - 将自动增量插入到第二列

转载 作者:行者123 更新时间:2023-11-29 06:16:50 25 4
gpt4 key购买 nike

我希望进行如下查询:

id |整数 |自动递增某事| varchar | 255

insert into `table` set something = concat('val', id);

使表格最终看起来像

1|val1
2|val2
3|val3...

除了每行的 id 最终总是 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)

关于mysql - 将自动增量插入到第二列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5972446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com