Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Trovare la riga successiva nella query SQL ed eliminarla solo se la riga precedente corrisponde

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