SQL 删除所有但最后一条记录(1到许多表)
例子
WITH cte AS (SELECT ProjectID,
ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn
FROM ProjectNotes
)
DELETE FROM cte WHERE rn > 1;
以上是 SQL 删除所有但最后一条记录(1到许多表) 的全部内容, 来源链接: utcz.com/z/325138.html
WITH cte AS (SELECT ProjectID,
ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn
FROM ProjectNotes
)
DELETE FROM cte WHERE rn > 1;
以上是 SQL 删除所有但最后一条记录(1到许多表) 的全部内容, 来源链接: utcz.com/z/325138.html