SQL 查询一个字段所有的之出现次数大于2的条数

2024-11-14 09:03:57
推荐回答(3个)
回答1:

with tmp(Name) as(
select '张三' union all
select '张三' union all
select '李四' union all
select '王五' union all
select '王五' union all
select '王五' union all
select '赵六' union all
select '赵六')
 
select count(*) from (
select Name from tmp group by Name having count(*)>1
) t

结果为:

回答2:

select name,count(*) from table_name group by name having count(*)>1;

回答3:

select count(name) ,name from table group by name having count(name)>1