如何通过删除重复的记录来清理表?
+----------+--------+------------+
| clientID | status | Insertdate |
+----------+--------+------------+
| 1 | new | 20191206 |
| 1 | new | 20191206 |
| 2 | old | 20191206 |
| 2 | old | 20191206 |
| 3 | new | 20191205 |
| 3 | new | 20191205 |
+----------+--------+------------+
我没有任何身份字段。
答案 0 :(得分:1)
请找到以下查询。您可以使用行号。
;WITH cte as (
select clientid
, status, Insertdate
, ROW_NUMBER() over (partition by clientid, status, Insertdate order by clientid) RowNumber
from Yourtable
)
delete from cte where RowNumber > 1
答案 1 :(得分:-1)
如果您正在运行MySQL数据库,希望这会有所帮助
SELECT clientID, status, Insertdate, count(*)
FROM table_name
GROUP BY clientID, status, Insertdate
having count(*) > 1