日期:2014-05-17  浏览次数:20806 次

求一个 删除的 SQL语句的写法
员工表   t_emp

工号 姓名 离职日期
001 张三 Null (空表示未离职)
002 李四 2006.11.10
003 王五 NUll
004 赵六 2006.12.20
.....

加班表   t_over

工号 加班日期
001 2006.11.15
002 2006.11.09 //这行保留
002 2006.11.15 //要删除这行
002 2006.11.16 //要删除这行
003 2006.11.15
004 2006.11.15
.....

现想将2006.11月离职后有加班的人的加班记录删除,
能否用一句SQL完成?

否则要用游标循环员工表,再单笔删除加班表的记录。

多谢!

------解决方案--------------------
delete from t_over t1
where exists
(
select 1 from t_emp t2
where t1.工号=t2.工号 and t2.离职日期> = '2006.11.01 ' and t2.离职日期 <= '2006.11.30 '
)

------解决方案--------------------
delete t_over x
where exists (select 'a '
from t_tmp y
where y.离职日期 is not null
and x.工号 = y.工号
and x.加班日期> y.离职日期)
------解决方案--------------------
DELETE FROM t_over
WHERE (工号, 加班日期) IN (SELECT 工号, 加班日期
FROM t_over a, t_emp b
WHERE a.工号 = b.工号(+) and a.离职日期 < b.加班日期)