【问题标题】:How do i copy data from one table to another table?如何将数据从一个表复制到另一个表?
【发布时间】:2016-05-12 09:50:12
【问题描述】:

我有 2 个表,国家和部门使用 ff 模式:

country               division
-----------           ------------
countrycode           divisioncode
contryname           countrycode
                      divisionname

我想将国家表中的数据复制到部门表中,其中国家代码进入部门代码,国家代码在部门表中,国家名称进入部门名称

例如,美国 - 美国以美国、美国、美国进入分区表。

【问题讨论】:

  • 插入 t2 (c1, c2, ...) select x1, x2, ... from t1

标签: mysql sql database


【解决方案1】:

使用INSERT INTO ... SELECT

查询

INSERT INTO division(divisioncode, countrycode, divisionname)
SELECT countrycode, countrycode, countryname
FROM country;

【讨论】:

  • 谢谢。我将其修改为INSERT INTO division (divisioncode, countrycode, divisionname) SELECT countrycode,countrycode, countryname FROM country;
【解决方案2】:
insert into division (divisioncode, countrycode, divisionname)
select t1.countrycode, t1.countrycode, t1.countryname
from country t1

见:http://dev.mysql.com/doc/refman/5.7/en/insert-select.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-24
    • 1970-01-01
    • 2011-05-16
    • 2014-05-02
    • 1970-01-01
    相关资源
    最近更新 更多