Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2495147
  • 博文数量: 308
  • 博客积分: 5547
  • 博客等级: 大校
  • 技术积分: 3782
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-24 09:47
个人简介

hello world.

文章分类

全部博文(308)

分类: Oracle

2020-11-20 10:34:38

    当对历史表的数据,每个字段都在不停的变化,合并找到当前最新的数据的SQL为

点击(此处)折叠或打开

  1. with tr_cust_register_info_tmp as
  2. (select rownum as rn, s.* from
  3. (select * from tr_cust_register_info_h ss
  4. where 1=1
  5. and 1=1 --追加过滤条件区域
  6. order by ss.imp_date desc) s --根据日期降序
  7. )
  8. select
  9.  substr(min(case when bank_code is null then null else lpad(rn,10) || bank_code end),11) bank_code,
  10.  substr(min(case when id_code is null then null else lpad(rn,10) || id_code end),11) id_code
  11.  from tr_cust_register_info_tmp

该语句的目的是,先根据日期进行降序排列,用行号rownum拼接数据内容,找最小的数据,然后截取前面的行号拿到最新的数据。
阅读(1677) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~