1. 程式人生 > >查詢表中多餘的重複記錄

查詢表中多餘的重複記錄

1.刪除表中多餘的重複記錄,只保留ID為最小的記錄.(多個欄位)

DELETE FROM XY_PRICEENTRY WHERE CUSABB IN
(SELECT CUSABB FROM XY_PRICEENTRY GROUP BY CUSABB HAVING COUNT(*)>1)
AND ITEM IN(SELECT ITEM FROM XY_PRICEENTRY GROUP BY ITEM HAVING COUNT(*)>1)
AND MINQTY IN(SELECT MINQTY FROM XY_PRICEENTRY GROUP BY MINQTY HAVING COUNT(*)>1)
AND ID NOT IN(SELECT MIN(ID) FROM XY_PRICEENTRY GROUP BY CUSABB,ITEM,MINQTY HAVING COUNT(*)>1)