点击(此处)折叠或打开
- with tr_cust_register_info_tmp as
- (select rownum as rn, s.* from
- (select * from tr_cust_register_info_h ss
- where 1=1
- and 1=1 --追加过滤条件区域
- order by ss.imp_date desc) s --根据日期降序
- )
- select
- substr(min(case when bank_code is null then null else lpad(rn,10) || bank_code end),11) bank_code,
- substr(min(case when id_code is null then null else lpad(rn,10) || id_code end),11) id_code
- from tr_cust_register_info_tmp
该语句的目的是,先根据日期进行降序排列,用行号rownum拼接数据内容,找最小的数据,然后截取前面的行号拿到最新的数据。