如何把一个表中ID相同的字段内容,复制到另一个表(200分)

  • 主题发起人 主题发起人 SmallGhost
  • 开始时间 开始时间
S

SmallGhost

Unregistered / Unconfirmed
GUEST, unregistred user!
我有2个表:<br>&nbsp; &nbsp; &nbsp; &nbsp;表一:<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; X<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 100<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 50<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br><br>&nbsp; &nbsp; &nbsp; &nbsp;表二:<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; Y<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>现在想用一句SQL语句修改“表二”中的Y字段,将Y字段修改为和“表一”的ID字段相同的值!<br>结果如下:<br>&nbsp; &nbsp; &nbsp; &nbsp;表二:<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; ID &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp; Y<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 100<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 50<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 50<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>&nbsp; &nbsp; &nbsp; &nbsp; 1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 100<br>&nbsp; &nbsp; &nbsp; &nbsp;—————————————————————————————<br>谢谢了!
 
update 表2<br>set Y=表1.X<br>from 表1 where 表1.ID=表2.ID
 
update 表2 set &nbsp;y= a.x from 表2<br>&nbsp; join 表1 a &nbsp;on id=a.id
 
sqserver :update 表2 &nbsp;set Y=表1.X &nbsp;from 表1 where 表1.ID=表2.ID &nbsp;<br><br>access :update 表2,表1 where 表1.ID=表2.ID &nbsp; &nbsp;set Y=表1.X
 
update Table2 set Y=Table1.X From Table1 Where Table1.ID=Table2.ID
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
900
SUNSTONE的Delphi笔记
S
D
回复
0
查看
824
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
后退
顶部