如何删除日期太近的记录?
How to delete record where date is too close?
我有一个 redshift table,我想删除时间戳太接近的记录。
以下table,我想删除第3行和第4行,因为日期接近第1行,其他字段相同。
col1 | col2 | col3
--------------------------
1 02:23 4
51 02:23 29
1 02:22 4
1 02:24 4
1 19:57 4
嗯。 . .您可以使用 lead()
:
select t.*
from (select t.*,
lead(col2) over (partition by col1, col3 over order by col2) as next_col2
from t
) t
where next_col2 is null or
next_col2 < col2 + interval '1 hour'. -- or whatever your cutoff is
我有一个 redshift table,我想删除时间戳太接近的记录。
以下table,我想删除第3行和第4行,因为日期接近第1行,其他字段相同。
col1 | col2 | col3
--------------------------
1 02:23 4
51 02:23 29
1 02:22 4
1 02:24 4
1 19:57 4
嗯。 . .您可以使用 lead()
:
select t.*
from (select t.*,
lead(col2) over (partition by col1, col3 over order by col2) as next_col2
from t
) t
where next_col2 is null or
next_col2 < col2 + interval '1 hour'. -- or whatever your cutoff is