我想将数据从一个字段复制到另一个mysql多行。我已经尝试过,但它不适用于所有和mysql甚至说“返回超过1行”
UPDATE agreement
SET _date2 = (SELECT Concat(SUBSTRING(_date, 7), '-', SUBSTRING(_date, 4, 2),
'-', SUBSTRING(_date, 1, 2)) AS newdd FROM agreementtemp);
答案 0 :(得分:10)
尝试
update `table_name` set destination_field=source_field
答案 1 :(得分:4)
尝试
update `tableName` set col1=col2
为此,两列都应属于同一个表,并且属于同一类型。
答案 2 :(得分:1)
您可以像这样更新一个字段:
update mytable set field1=field2;
答案 3 :(得分:1)
更新项目,月份SET items.price = month.price WHERE items.id = month.id;
或
UPDATE TABLE_1
LEFT JOIN TABLE_2
ON TABLE_1.COLUMN_1= TABLE_2.COLUMN_2
SET TABLE_1.COLUMN = EXPR
WHERE TABLE_2.COLUMN2 IS NULL
在你的情况下,它将是
UPDATE agreement a1
JOIN agreementtemp a2
ON a1.id = a2.id
SET a1._date2 = Concat(SUBSTRING(a2._date, 7), '-', SUBSTRING(a2._date, 4, 2) , '-', SUBSTRING(a2._date, 1, 2));