由於一次操作失誤,給表中插入了多條重復的數據,所以就需要刪除重復的數據只保留一條,一時想不到好方法,各種查資料,終於找到了,特意寫到這里,方便以后自己用~
查詢:
select A.n_PatentID,A.s_OtherFileName,A.s_FileName FROM TB_OtherFiles A, (SELECT n_PatentID,s_OtherFileName,s_FileName FROM TB_OtherFiles GROUP BY n_PatentID,s_OtherFileName,s_FileName HAVING COUNT(1)>=2 ) AS B WHERE A.s_OtherFileName=B.s_OtherFileName AND A.n_PatentID=B.n_PatentID AND A.s_FileName=B.s_FileName AND A.n_PatentID >0 order by n_PatentID
刪除:
DELETE T FROM (SELECT n_PatentID,s_OtherFileName,s_FileName,s_recycle, ROW_NUMBER()OVER(PARTITION BY n_PatentID,s_OtherFileName,s_FileName ORDER BY RAND()) AS RN FROM TB_OtherFiles where n_PatentID>0) AS t WHERE RN>1