您還沒有給出表結構,但如果我做了一個虛表所示:
create table t42 (id number, grp_id number, dt date);
insert into t42 values (1, 1, timestamp '2014-01-05 01:20:00');
insert into t42 values (2, 1, timestamp '2014-01-05 01:15:13');
insert into t42 values (3, 1, timestamp '2014-01-05 01:12:13');
insert into t42 values (4, 1, timestamp '2014-01-05 01:07:13');
insert into t42 values (5, 1, timestamp '2014-01-05 01:06:13');
那麼這會給你組中每一行相比,其(分析)最大的年齡:
select grp_id, id, dt, max(dt) over (partition by grp_id) - dt as age
from t42
order by id;
GRP_ID ID DT AGE
---------- ---------- ------------------- ------------
1 1 2014-01-05 01:20:00 0
1 2 2014-01-05 01:15:13 .00332175926
1 3 2014-01-05 01:12:13 .00540509259
1 4 2014-01-05 01:07:13 .00887731481
1 5 2014-01-05 01:06:13 .00957175926
你可以使用它作爲一個內部查詢並過濾掉的記錄長達10分鐘的時候:
select grp_id, id, dt
from (
select grp_id, id, dt, max(dt) over (partition by grp_id) - dt as age
from t42
)
where age > (10*60)/(24*60*60)
order by id;
GRP_ID ID DT
---------- ---------- -------------------
1 4 2014-01-05 01:07:13
1 5 2014-01-05 01:06:13
然後你可以根據需要使用那些刪除/更新。從您的問題中不清楚您的組/分區是否已經從內部查詢計算出來;如果是這樣,你可以使用,而不是我的t42
表。 (當然,更改列名等)。