简体   繁体   English

将数据从一个表复制到另一个表并添加其他数据

[英]Copy Data From One Table To Another AND Adding Additional Data

I have a temp table and a regular table in my database. 我的数据库中有临时表和常规表。 The column name and types are identical, except the regular table has an extra field. 列名和类型是相同的,除了常规表有一个额外的字段。 I am trying to write a query that copies the information from the temp table into the regular table and adds data into the addition field all in one query. 我正在尝试编写一个查询,将temp表中的信息复制到常规表中,并在一个查询中将数据添加到添加字段中。

I understand how to copy columns from one table to another (eg INSERT INTO TABLE 1 (col 1, etc..) SELECT TABLE2), but how do i do this AND then add in a the value for the new field? 我理解如何将列从一个表复制到另一个表(例如INSERT INTO TABLE 1(col 1等)SELECT TABLE2),但我该怎么做然后添加新字段的值?

Thanks for your help. 谢谢你的帮助。

 INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *, NULL from TABLE2

要么

 INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *, the_default_date_here from TABLE2

If you want your values 如果你想要你的价值观

INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *,concat('".$value."') as value1 from TABLE2

Date means just put now() INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *,now() from TABLE2 Date表示刚刚放入now() INSERT INTO TABLE1 (col 1, col2,..., the_extra_col) SELECT *,now() from TABLE2

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

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