1. 程式人生 > >mysql 資料表中查詢重複記錄

mysql 資料表中查詢重複記錄

1、單個欄位

查詢所有重複資料

select * from ActivityWinUser where (UID) in(select UID from ActivityWinUser group by UID having count(*)>1);

去重

delete from table where Name in(select Name from table group by Name having count(*)>1);

2、多個欄位

查詢所有重複資料

select * from table a where (a.UID,a.ActivityID)  in (select UID,ActivityID from table group by UID,ActivityID having count(*) > 1) ;

3、去除重複記錄

select *, count(distinct name) from table group by name
---------------------
作者:想你時的孤獨
來源:CSDN
原文:https://blog.csdn.net/u013091013/article/details/51333155
版權宣告:本文為博主原創文章,轉載請附上博文連結!

 

注:select ex_id from zqc_log_exzdcs where d_created_date>'2018-12-20 17:12:00' and d_created_date<'2018-12-20 17:15:00' group by ex_id having count(*)>1;