mad*_*xxx -2 sql t-sql sql-server duplicates
我在临时表中有重复的行主要是因为有一些日期值是秒/毫秒彼此不同.
例如:
2018-08-30 12:30:19.000
2018-08-30 12:30:20.000
这是导致重复的原因.
我怎样才能保留其中一个值?我们说更高的一个?
谢谢.
好吧,一种方法是使用lead():
select t.*
from (select t.*, lead(ts) over (order by ts) as next_ts
from t
) t
where next_ts is null or
datediff(second, ts, next_ts) < 60; -- or whatever threshold you want
Run Code Online (Sandbox Code Playgroud)