One 、 Demand background
When processing data , Because the primary key of the table is data_seq_id, A self defined sequence , for example ：INWDN000827....
These data need to be maintained by users , If the user maintains two copies , Because it's inevitable that the primary key is designed like this . How to remove duplicate data ？
Two 、 Look for duplicate data
adopt group by count Duplicate data found .
3、 ... and 、update Odd row flag by N
How to find odd or even rows ？
select * from( select @rownum := @rownum + 1 as row_num, t.* from m_bis_data_d t,( select @rownum := 0 ) tmp_table) t where t.row_num % 2 = 1
Through this sql You can find the odd number line data_seq_id . And then take it. update Just drop it .
Four 、 summary
In fact, to solve this problem should be to solve it fundamentally , You can't be so casual , This should be taken into account at the beginning of setting the primary key . My idea is to use value then md5 Generate primary key , That is, there will be no duplication, and it can also ensure that there will be no duplication of data .