[英]Copy Data from one table to another table
我有两个具有不同行数的表,我希望复制一列数据并将其插入到第二个表中。 我该怎么办? 我知道如何在具有相同列数的两个表中插入数据,但是在这种情况下应该怎么办?
TABLE A
ID | Exp | T/F | RATE |
======================
1 | 11 | T | 0.45|
-----------------------
: : :
Table B
ID | Year | Exp | Sex | V | VI | VII|
======================================
1 | 2011 | 11 | M | x | x | c |
--------------------------------------
: : : : : : :
在示例中,我希望将[费率]从表A插入表B。该怎么办? 谢谢。
这是一个update
操作。
但是,首先,如果该列不存在,则需要添加它:
alter table b add rate decimal(4, 2); -- or whatever the appropriate type is
然后,您可以对其进行更新。 假设id
列相同:
update b
set rate = a.rate
from b join
a
on b.id = a.id;
--In which column you want to insert rate in second table
--in my guess try this it might help you
Insert into [TABLE A] (--the column names where you want to insert)
Select (--the column what you want to select) From [TABLE B] ;
--Example
Insert into [Table A] (ID,Exp)
Select (Id,Exp) From [Table B]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.