sql server - Deleting duplicates in a time series -
i have large set of measurements taken every 1 millisecond stored in sql server 2012 table. whenever there 3 or more duplicate values in rows delete middle duplicates. highlighted values in image of sample data ones want delete. there way sql query?
you can using cte
, row_number
:
with ctegroup as( select *, grp = row_number() over(order ms) - row_number() over(partition value order ms) yourtable ), ctefinal as( select *, rn_first = row_number() over(partition grp, value order ms), rn_last = row_number() over(partition grp, value order ms desc) ctegroup ) delete ctefinal rn_first > 1 , rn_last > 1
Comments
Post a Comment