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

版权声明:本文章的所有内容,包括文字、图片,均为原创。转载请注明出处。作者首页:https://blog.csdn.net/songxinfeng1989 https://blog.csdn.net/songxinfeng1989/article/details/81906287

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';


 

猜你喜欢

转载自blog.csdn.net/songxinfeng1989/article/details/81906287