sql >> Base de Datos >  >> RDS >> Sqlserver

Encontrar la siguiente fila en la consulta SQL y eliminarla solo si la fila anterior coincide

with C as
(
  select ID,
         row_number() over(order by DT) as rn
  from YourTable
)
delete C1
from C as C1
  inner join C as C2
    on C1.rn = C2.rn-1 and
       C1.ID = C2.ID

SE-Datos