Sqlserver
 sql >> Base de Dados >  >> RDS >> Sqlserver

Encontrar a próxima linha na consulta SQL e excluí-la somente se a linha anterior corresponder

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-Data