简体   繁体   English

通过mysql查询将1列复制到另一列

[英]Copy 1 column to another by mysql query

I have mysql database with following table... 我有以下表的mysql数据库...

| id | amount | tax |
+----+--------+-----+
|  1 | 500    |     |
+----+--------+-----+
|  2 | 100    |     |
+----+--------+-----+

I have to delete amount column but before doing that i want to shift all data of amount row from amount row to tax row. 我必须删除金额列,但在此之前我想将金额行的所有数据从金额行转移到税行。 How can it be done using mysql query? 怎么用mysql查询呢? Please help. 请帮忙。

UPDATE mytable SET tax = amount

你可以删除它之后

ALTER TABLE mytable DROP COLUMN amount; 
UPDATE yTable SET tax = amount

Or to rename instead of copying (much faster): 或者重命名而不是复制(更快):

ALTER yTable CHANGE amount tax YOURDATATYPE;

Delete tax before renaming. 重命名前删除税。

update TABLE_NAME set tax=amount;

会做。

update your_table_name set tax=amount

you can delete the column data 您可以删除列数据

UPDATE your_table_name SET amount = NULL WHERE amount is not null;

or you can delete column itself 或者您可以删除列本身

ALTER TABLE your_table_name DROP COLUMN amount

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM