获取系统多少记录中 时间最新的一条sql语句,并更新对应的表的状态

 

1.获取job表中多条记录中的最新的一条记录

/*Dialect*/select a.* 
from job a
where not exists(select 1 
from job b
where b.deptcode=a.deptcode and b.stime>a.stime) 
and a.ismaster=1 and a.deptcode in ('DP0205','DP41','DP5600') 
order by stime desc;

 

2、执行job表中最新表的状态值,可重新同步数据

update job set synstatus=0 where id in (select a.id
from job a
where not exists(select 1 
from job b
where b.deptcode=a.deptcode and b.stime>a.stime) 
and a.ismaster=1 and a.deptcode in ('DP0205','DP41','DP5600'))

你可能感兴趣的:(oracle)