Mysql 将一表的一字段数据填到对应另一表字段中

任务为:

将tests_copy1中hm字段填上相应的数据,该数据来源于spacegroups中的hm数据。

要求tests_copy1中的spacegroups_id与spacegroups中的number值对应。

 

 

 

 

一下两种方法:

1、

INSERT into 
tests_copy1_copy2
(chem_formula,natoms,nsites,
ntypes,x1,x2,x3,y1,y2,y3,z1,
z2,z3,sxx,syy,szz,sxy,syz,
szx,spacegroup_id,volume_pa,
energy_pa,
magmom_pa,label,
entry_id,id1,id2,

hm) 

SELECT 

tests_copy1.chem_formula,
tests_copy1.natoms,
tests_copy1.nsites,
tests_copy1.ntypes,
tests_copy1.x1,
tests_copy1.x2,tests_copy1.x3,
tests_copy1.y1,tests_copy1.y2,
tests_copy1.y3,tests_copy1.z1,
tests_copy1.z2,tests_copy1.z3,
tests_copy1.sxx,tests_copy1.syy,
tests_copy1.szz,tests_copy1.sxy,
tests_copy1.syz,
tests_copy1.szx,tests_copy1.spacegroup_id,
tests_copy1.volume_pa,tests_copy1.
energy_pa,
tests_copy1.magmom_pa,
tests_copy1.label,tests_copy1.entry_id,
tests_copy1.id1,
tests_copy1.id2,

spacegroups.hm
 from 
tests_copy1 
left join  
spacegroups on tests_copy1.spacegroup_id = spacegroups.number

 

方法二、

update 

tests_copy1_copy2 ,spacegroups 
set 

tests_copy1_copy2.hm =spacegroups.hm
where 

tests_copy1_copy2.spacegroup_id=spacegroups.number

 

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

萌新待开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值