zoukankan      html  css  js  c++  java
  • MYSQL用一个表中的字段批量更新另一个表中的字段

    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
  • 相关阅读:
    11.26
    数组
    JavaScript
    2018.11.26
    input标签
    HPH 函数
    jQuery
    19/1/3数组
    2018/12/26//循环体
    12/25
  • 原文地址:https://www.cnblogs.com/macliu/p/12274169.html
Copyright © 2011-2022 走看看