背景:
今天在用crawler爬數據的時候,第一次爬的時候被我意外中止了,後來又重新開始,但卻忘了清除一些垃圾數據,導致在wordlocation 表中產生了不少重複的記錄。
wordlocation 表的定義如下 wordlocation(urlid, wordid, location),其中(urlid, wordid) 應該是唯一的。
要求:
從wordlocation 表中刪除多餘的重複數據
方案:
創建一個結構一模一樣的表wl_new,然後執行下面的語句
INSERT INTO wl_new SELECT * FROM wordlocation GROUP BY urlid, wordid
最後的GROUP BY 保證了(urlid, wordid)的唯一性
然後再刪除wordlocation表中的所有數據,把wl_new的所有數據插入到wordlocation,最後刪除wl_new即可