使用带有自定义列的select插入多行

时间:2015-09-08 12:22:44

标签: mysql

我想在同一张表中克隆客户1(Alex)的数据,但是客户2(TOM):

+----+----------+-------+--------+-------+
| ID | Customer | INPUT | OUTPUT |  WIN  |
+----+----------+-------+--------+-------+
|  1 | Alex     | test1 | test2  | test3 |
|  2 | Alex     | test5 | test8  | test8 |
+----+----------+-------+--------+-------+

这不起作用:

INSERT INTO my_table (Customer,INPUT,OUTPUT,WIN) 
VALUES "TOM", (SELECT INPUT,OUTPUT,WIN FROM my_table)

1 个答案:

答案 0 :(得分:1)

SELECT

中加入更改后的值
INSERT INTO my_table (Customer,INPUT,OUTPUT,WIN) 
 SELECT "TOM", INPUT,OUTPUT,WIN FROM my_table;

我还要添加WHERE

INSERT INTO my_table (Customer,INPUT,OUTPUT,WIN) 
 SELECT "TOM", INPUT,OUTPUT,WIN FROM my_table WHERE Customer='Alex';