要刪除重復數據,可以使用以下步驟:
SELECT *, COUNT(*)
FROM table_name
GROUP BY column1, column2, ...
HAVING COUNT(*) > 1;
DELETE FROM table_name
WHERE id IN (
SELECT id
FROM (
SELECT id, ROW_NUMBER() OVER (PARTITION BY column1, column2, ... ORDER BY id) AS rnum
FROM table_name
) t
WHERE t.rnum > 1
);
在上面的語句中,column1, column2, ...
是用來識別重復數據的列,id
是表的主鍵字段。
請注意,在執行刪除操作之前,請務必備份數據以防止意外刪除。