如何删除数据库中的冗余数据
发布网友
发布时间:2022-04-28 11:53
我来回答
共1个回答
热心网友
时间:2022-05-03 13:07
删除所有大于你
设置有数的冗余组
DELETE
FROM Customers
WHERE ID IN
(SELECT ID
FROM
(SELECT ID, LastName, FirstName,
RANK() OVER (PARTITION BY LastName,
FirstName ORDER BY ID) AS SeqNumber
FROM
(SELECT ID, LastName, FirstName
FROM Customers
WHERE (LastName, FirstName) IN
(SELECT LastName, FirstName
FROM Customers
GROUP BY LastName, FirstName
HAVING COUNT(*) > 3)))
WHERE SeqNumber > 3);
As you can see, using the RANK() function allows you to eliminate plicates in a
single SQL statement and gives you more capabilities by extending the power of
your
queries.
正如你所见使用Rank()可以消除冗余数据而且能给你很大的可伸展性