标签:查询 ble 员工 group ide having dep 记录 var
从一个表中删除被另外一个表引用的记录。
考虑下面的DEPT_ACCIDENTS表,其中每行代表生产过程中的一次事故,每行记录了发生的部门以及事故类型。
create table dept_accidents
(deptno integer,
accident_name varchar(20));
insert into dept_accidents values (10,‘BROKEN FOOT‘);
insert into dept_accidents values (10,‘FLESH WOUND‘);
insert into dept_accidents values (20,‘FIRE‘);
insert into dept_accidents values (20,‘FIRE‘);
insert into dept_accidents values (20,‘FLOOD‘);
insert into dept_accidents values (30,‘BRISED GLUTE‘);
使用子查询和聚集函数count来查出发生了三次事故以上的部门,然后将这些部门的员工全部删除。
delete from emp
where deptno in
(select deptno from dept_accidents group by deptno having count(*)>=3);
标签:查询 ble 员工 group ide having dep 记录 var
原文地址:http://www.cnblogs.com/liang545621/p/7518759.html