A表
user_id,
dept_id,
......
B表
user_id,
dept_id,
......
员工考勤表 部门id字段缺失,批量修复B表数据,填充部门id
--A表
--user_id,
--dept_id,
--......
--B表
--user_id,
--dept_id,
--......
UPDATE B b
INNER JOIN A a ON a.user_id = b.user_id
SET a.dept_id = b.dept_id
WHERE
B.`dept_id` IS NULL;
--解决建表不规范,两张表同一个字段编码不一致问题
--a.user_id = CONVERT ( b.user_id USING utf8 ) COLLATE utf8_unicode_ci
--CONVERT ( b.user_id USING utf8 ) COLLATE utf8_general_ci
UPDATE B b
INNER JOIN A a ON a.user_id = CONVERT ( b.user_id USING utf8 ) COLLATE utf8_unicode_ci
SET a.dept_id = b.dept_id
WHERE
B.`dept_id` IS NULL;