接到任务,查询2021年之前的US_ADDCONSIGN表中用户信息。
同时同事告知,有用户重复注册所以信息有重复的,要求重复的信息中获取目前仍有效,且注册时间最早的那一条记录。
select * from (select row_number() over (partition by certno order by consigndate) rn, a.* from US_ADDCONSIGN a where 1=1 and state=1 ) where rn=1 and to_date(consigndate,'yyyymmdd')<to_date('20210101','yyyymmdd');