SQL仅返回重复的记录 [英] SQL Return only duplicate records

查看:50
本文介绍了SQL仅返回重复的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想返回在SQL的全名"和地址"列中具有重复值的行.因此,在示例中,我只希望返回前两行.我该如何编码?

I want to return rows that have duplicate values in both Full Name and Address columns in SQL. So in the example, I would just want the first two rows return. How do I code this?

推荐答案

为什么返回重复值?只需合计并返回计数:

Why return duplicate values? Just aggregate and return the count:

select fullname, address, count(*) as cnt
from t
group by fullname, address
having count(*) >= 2;

这篇关于SQL仅返回重复的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆