答案 0 :(得分:1)
问题不明确,但如果您要删除超过3个月的记录,则应执行以下操作:
DELETE from Tablex
WHERE datediff(m,InsertDt , getdate())> 3
答案 1 :(得分:1)
试试这个:
DELETE
FROM Tablex
INNER JOIN (SELECT max(InsertDt ) LastDate, id FROM Tablex GROUP by id) LastDates ON LastDates.id = Tablex.id
WHERE InsertDt < dateadd(m,-3,LastDates.LastDate)