mysql数据库之批量更新语法

落花浮王杯 提交于 2019-11-30 12:06:07

1.insert into ...on duplicate key update批量更新

 

2.replace into 批量更新

 

3.临时表

SELECT * FROM `makemoneyinfo` where dakuanaccount = accountnumber order by creationtime 


select no,bank2 from sap_cw_notice where no in(
SELECT bankid FROM `makemoneyinfo` where dakuanaccount = accountnumber )

dakuanaccount(财务账号)

update  makemoneyinfo set dakuanaccount = 
case when no = '' then ''  end,
dakuanaccount = 
end

--批量更新 列的位置 ,从一个表导入另一个(只关心列的位置)
replace into makemoneyinfo( name, id) select rname, rtitle, rmood from tb2;


创建临时表,先更新临时表,然后从临时表中update

select * from tmp;

-- 创建临时表
CREATE TEMPORARY TABLE tmp ( NO VARCHAR ( 100 ) PRIMARY KEY, bank2 VARCHAR ( 50 ) );
--插入数据 
INSERT INTO tmp SELECT NO
,
bank2 
FROM
    sap_cw_notice 
WHERE
    NO IN ( SELECT bankid FROM `makemoneyinfo` WHERE dakuanaccount = accountnumber );
    
    -- 更新目标表数据
UPDATE makemoneyinfo,
tmp 
SET makemoneyinfo.dakuanaccount = tmp.bank2 
WHERE
    makemoneyinfo.bankid = tmp.NO;

4.使用mysql 自带的语句构建批量更新

 

参考链接:

https://blog.csdn.net/h330531987/article/details/79114563

https://www.cnblogs.com/PatrickLiu/p/6385167.html

https://www.cnblogs.com/c-961900940/p/6197878.html

https://www.runoob.com/sql/sql-insert-into-select.html

 

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!