-- DELETE语句 -- 删除10部门中,工龄超过20年的员工记录 DELETE FROM t_emp WHERE deptno=10 AND DATEDIFF(NOW(),hiredate)/365>=20;
-- 删除20部门中工资最高的员工记录 DELETE FROM t_emp WHERE deptno=20 ORDER BY sal+IFNULL(comm,0) DESC LIMIT 1;
-- 删除SALES部门和该部门的全部员工记录 DELETE e,d FROM t_emp e JOIN t_dept d ON e.deptno=d.deptno WHERE d.dname="SALES";
-- 删除每个低于部门平均底薪的员工记录 DELETE e FROM t_emp e JOIN (SELECT deptno,AVG(sal) AS avg FROM t_emp GROUP BY deptno) t ON e.deptno=t.deptno AND e.sal<t.avg;
-- 删除员工King和他的直接下属的员工记录,用表连接实现 DELETE e FROM t_emp e JOIN (SELECT empno FROM t_emp WHERE ename="KING") t ON e.mgr=t.empno OR e.empno=t.empno; TRUNCATE TABLE t_emp;
原文:https://www.cnblogs.com/waterr/p/13959040.html