SQL语句关联删除

来源:百度知道 编辑:UC知道 时间:2024/06/04 03:19:30
delete d from tb_clfb d
where not exists
(
select 1 from
(
select c.CAR_NO,a.rpt_time
from tb_station_train a,tb_xt_borderstat b,tb_station_car c
where a.stn_code=b.zmlm and
a.aei_no=b.aei_no and
a.train_dir=b.train_dir and
b.jcj=0 and a.org_train_flag='H' AND
a.rpt_time=c.rpt_time
)
d.ch=car_no and d.BJSJ<rpt_time
)

帮忙看看以上代码对不对,谢谢!

非要这么写的话
倒数第二行改为where d.ch=a.car_no and d.BJSJ<c.rpt_time)
如果用的是SQL SERVER 子查询最后需要select...from (select from...) AS Temp_tabname....

where not exists
改为
where d not exists
要说明哪个字段