oracle 在一张日志表中,同一个ID 有多条记录,每个ID只获取最新时间的记录

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/T_Mac9334/article/details/83095982

查询方法

select *

from (select t.*,

row_number() over(partition by t.campaignid order by t.assigndate desc) rn

from tablea t) c

where rn = 1

更新查询的结果集

在更新查询出来的结果集

update tablea

set VALID = 'Q'

where (CAMPAIGNID, DEALERID, CUSTOMERID, CREATE_DATE) in

(select a.CAMPAIGNID, a.DEALERID, a.CUSTOMERID, a.CREATE_DATE

from (select *

from (select t.*, row_number() over (partition by t.campaignid order by t.assigndate desc) rn

from tablea t) c

where rn = 1) a);

猜你喜欢

转载自blog.csdn.net/T_Mac9334/article/details/83095982