首页 > 数据库技术 > 详细

MYSQL用一个表中的字段批量更新另一个表中的字段

时间:2020-02-07 20:07:10      阅读:120      评论:0      收藏:0      [点我收藏+]
select ta.id,ta.parent_id,ta.name,ta.level, mr.id as r_id,mr.parent_id as r_pid,mr.name as r_name,mr.type as r_type,mr.provice_id as r_provice_id from test_movhome.area ta, movhome.region mr where ta.name = mr.name


# 批量替换,用一个表中的字段 更新 另一个表中的字段
update test_movhome.cinema a inner join 
(select ta.id,ta.parent_id,ta.name,ta.level, mr.id as r_id,mr.parent_id as r_pid,mr.name as r_name,mr.type as r_type,mr.provice_id as r_provice_id from test_movhome.area ta, movhome.region mr where ta.name = mr.name) b 
on a.region_id = b.r_id set a.region_id = b.id


# 批量替换,用一个表中的字段 更新 另一个表中的字段
update test_movhome.cinema a, 
(select ta.id,ta.parent_id,ta.name,ta.level, mr.id as r_id,mr.parent_id as r_pid,mr.name as r_name,mr.type as r_type,mr.provice_id as r_provice_id from test_movhome.area ta, movhome.region mr where ta.name = mr.name) b 
set a.new_region_id = b.id, a.other_filed = b.other_filed
where a.region_id = b.r_id

# 批量设置一个表中的字段为一个固定的值
update test_movhome.cinema a set a.new_region_id = 0

 

MYSQL用一个表中的字段批量更新另一个表中的字段

原文:https://www.cnblogs.com/macliu/p/12274169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!