文章标题
2017-07-10 14:55
246 查看
场景:
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不相等。
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)