1. 修改字符集:
查看数据库字符集 show VARIABLES like 'character%'; ALTER TABLE yljg DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 修改数据库字符集 ALTER TABLE dept DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; 查看 列字符集 SHOW FULL COLUMNS FROM dept; SHOW FULL COLUMNS FROM yljg; 修改列字符集 ALTER TABLE yljg CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;
2. left join 跨表update, 表内互相update
SELECT * FROM yljg t left join dept B on t.JGZDYBM = B.DEPTCODE WHERE B.parentcode != 0 AND t.xzqhdm IN ('370724' , ' 370725', '370789') SELECT * from dept WHERE parentcode != '0' UPDATE yljg t, dept B SET t.SJJGBM = B.PARENTCODE WHERE t.JGZDYBM = B.DEPTCODE AND xzqhdm IN ('370724' , ' 370725', '370789') SELECT * FROM yljg WHERE xzqhdm IN ('370724' , ' 370725', '370789') AND SJJGBM != '0' UPDATE yljg t SET sjjgid = (SELECT JGMC FROM yljg m WHERE t.SJJGBM = m.JGZDYBM) WHERE t.SJJGBM != '0' AND t.xzqhdm IN ('370724' , ' 370725', '370789') UPDATE yljg t SET xzjddm = (SELECT xzjddm FROM yljg m WHERE t.SJJGBM = m.JGZDYBM) WHERE t.SJJGBM != '0' AND t.xzqhdm IN ('370724' , ' 370725', '370789') UPDATE yljg t SET xzjdmc = (SELECT xzjdmc FROM yljg m WHERE t.SJJGBM = m.JGZDYBM) WHERE t.SJJGBM != '0' AND t.xzqhdm IN ('370724' , ' 370725', '370789')