文章标题

xiaoxiao2021-02-28  149

场景: a0表是a表的源表。a表每天都把a0表的全部数据拿过来插入。(因此a的数据量很大,一般需要创建相应的索引) 假设t4是类似于日期的字段,需要找到t1,t2两个查询条件下的对象在一系列t4下的变动记录。 举例: T1 T2 T3 T4 1 1 1 1 1 1 1 2 1 1 2 3 1 1 2 4 1 1 1 5 … 显然,想要的结果分别为第一行,第三行,第五行,这些行与上一行的T3不相等。

select aa.* from (select rownum as rn,a.* from (select t1,t2,t3,t4 from t where t1='t1' and t2='t2'order by t4 asc) a)aa, (select rownum as rn,b.* from (select t1,t2,t3,t4 from t where t1='t1' and t2='t2'order by t4 asc) b)bb where (aa.rn=bb.rn+1 and aa.t3<>bb.t3) or (aa.rn=1 and bb.rn=1)
转载请注明原文地址: https://www.6miu.com/read-26646.html

最新回复(0)