update dept join (select COUNT(emp_id) as n,dept_id from employee GROUP BY dept_id) as e on e.dept_id = dept.dept_id set emp_count = e.n;
关联删除 有了关联更新,肯定有时候也想关联删除了
delete from t1 where 条件 delete t1 from t1 where 条件 delete t1 from t1,t2 where 条件 delete t1,t2 from t1,t2 where 条件
语法:
delete A from A inner join B on A.CID=B.CID where B.cp = 2 and A.x=xx;
我自己这边使用的例子
update schedule_detail a INNER JOIN (select schedule_code,material_code,move_out from schedule_detail where schedule_code='ANE24A0014' and move_out>0) b on b.material_code=a.material_code set a.move_in = b.move_out where a.schedule_code='ANE24A0012-1' and move_in<0