sql查找一列中某一数值出现次数大于2的记录
需要用group by中的having子句。
1、如test表中有如下数据:
2、现要查出dept出现2次以上的dept。可用如下语句:
select dept from test group by dept having count(*) >2;3、查询结果:
SQL 查询一个字段所有的之出现次数大于2的条数
with tmp(Name) as(select '张三' union allselect '张三' union allselect '李四' union allselect '王五' union allselect '王五' union allselect '王五' union allselect '赵六' union allselect '赵六') select count(*) from (select Name from tmp group by Name having count(*)>1) t结果为: