我有一个表ABC
ID no no2 no3 no4
1 1 Abc P P
2 2 xyz A P
3 3 xsc A A
4 4 xcs P P
我想在ABC表中插入
我的查询就像这样
插入ABC(no,no1,no2,no3,no4)值((从ABC + 1中选择max(no)),' XXX',' XXX1',& #39; XXXX2&#39)
答案 0 :(得分:1)
您可以使用INSERT语句,如:
insert into ABC (no,no2,no3,no4) select max(no)+ 1,'XXX','XXX1','XXXX2' from ABC;
mysql> create table ABC(id int primary key auto_increment,no int, no2 varchar(20),no3 varchar(20),no4 varchar(20));
Query OK, 0 rows affected (0.46 sec)
mysql> insert into ABC values
-> (1,1,'Abc','P','P'),
-> (2,2,'xyz','A','P'),
-> (3,3,'xsc','A','A'),
-> (4,4,'xcs','P','P');
Query OK, 4 rows affected (0.18 sec)
Records: 4 Duplicates: 0 Warnings: 0
mysql> insert into ABC (no,no2,no3,no4) select max(no)+ 1,'XXX','XXX1','XXXX2' from ABC;
Query OK, 1 row affected (0.16 sec)
Records: 1 Duplicates: 0 Warnings: 0
mysql> select * from ABC;
+----+------+------+------+-------+
| id | no | no2 | no3 | no4 |
+----+------+------+------+-------+
| 1 | 1 | Abc | P | P |
| 2 | 2 | xyz | A | P |
| 3 | 3 | xsc | A | A |
| 4 | 4 | xcs | P | P |
| 5 | 5 | XXX | XXX1 | XXXX2 |
+----+------+------+------+-------+
5 rows in set (0.00 sec)