mysql查询某一个或几个字段重复值是哪个,重复几条

select 列名1,count(1) as count 
from 表名
group by  列名1
having count>1  and 其他条件

 

select 列名1,列名2,count(1) as count 
from 表名
group by  列名1,列名2 
having count>1  and 其他条件
 

原理:先按照要查询出现重复数据的列,进行分组查询。count>1代表出现2次或2次以上。

示例:

/*查询重复数据*/
select serialnum,cdate,count(*) as count 
from m_8_customer_temp_20180820bak 
group by serialnum,cdate having  count>1 and cdate>='2018-08-20 00:00:00';