通过 mysql 查询将 1 列复制到另一列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6827441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Copy 1 column to another by mysql query
提问by seoppc
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? Please help.
我必须删除金额列,但在此之前我想将金额行的所有数据从金额行转移到税行。如何使用 mysql 查询来完成?请帮忙。
回答by Haim Evgi
UPDATE mytable SET tax = amount
after you can remove it
在你可以删除它之后
ALTER TABLE mytable DROP COLUMN amount;
回答by Jacob
UPDATE yTable SET tax = amount
Or to rename instead of copying (much faster):
或者重命名而不是复制(更快):
ALTER yTable CHANGE amount tax YOURDATATYPE;
Delete tax before renaming.
重命名前删除税。
回答by Jerry Tian
update TABLE_NAME set tax=amount;
will do.
会做。
回答by Sunil Kumar
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