读书人

求一个 剔除的 SQL语句的写法

发布时间: 2011-12-12 22:59:56 作者: rapoo

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

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

加班表 t_over

工号加班日期
0012006.11.15
0022006.11.09//这行保留
0022006.11.15//要删除这行
0022006.11.16//要删除这行
0032006.11.15
0042006.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.加班日期)

读书人网 >oracle

热点推荐