如何删除其经理在纽约的emp?
员工表
empid name salary location
101 john 10000 newyork
102 pavan 25000 newyork
103 laxman 10000 ahmedabad
104 ram 15000 usa
105 arjun 30000 washington
106 gopal 12000 washington
表部门专栏
empid dept managerid
101 a 102
102 a
103 a 102
104 b 105
105 b
106 b 105
答案 0 :(得分:5)
这将适用于某些RDBMS,但不是全部,如果您能告诉我们您使用的是哪种,我们可以提供更完整的解决方案
DELETE FROM employee
WHERE emp_id IN (SELECT emp_id FROM department
WHERE manager_id IN
(SELECT emp_id FROM employees WHERE location = "newyork"));
答案 1 :(得分:4)
SQL Server解决方案
delete E
from Employee M
join department D on D.managerid = M.empid
join Employee E on E.empid = D.empid
where M.location = 'usa';
答案 2 :(得分:1)
delete from emplyoee where empid in(
select e.empid from emplyoee e
left outer join emplyoee e1 on e.empid=e1.empid
left outer join department d on d.managerid=e1.empid
where e1.location='usa'
)