27_MySQL数字函数(重点)
/* SALES部门中工龄超过20年的,底薪增加10% SALES部门中工龄不满20年的,底薪增加5% ACCOUNTING部门,底薪增加300元 RESEARCH部门里低于部门平均底薪的,底薪增加200元 没有部门的员工,底薪增加100元 */ UPDATE t_emp e1 LEFT JOIN t_dept d1 ON e1.deptno = d1.deptno LEFT JOIN (SELECT e.deptno AS deptno,AVG( e.sal ) AS avg FROM t_emp e LEFT JOIN t_dept d ON e.deptno = d.deptno AND d.dname = "RESEARCH" ) t ON e1.deptno = t.deptno SET e1.sal = ( CASE WHEN d1.dname = "SALES" AND DATEDIFF( NOW( ), hiredate ) / 365 >= 20 THEN e1.sal * 1.1 WHEN d1.dname = "SALES" AND DATEDIFF( NOW( ), hiredate ) / 365 > 20 THEN e1.sal * 1.05 WHEN d1.dname = "ACCOUNTING" THEN e1.sal + 300 WHEN e1.sal <= t.avg THEN e1.sal + 200 WHEN e1.deptno IS NULL THEN e1.sal + 100 ELSE e1.sal END ); )