POSTGRESQL仅选择至少有一个重复电话号码的重复帐户
我想获得以下示例数据(POSTGRESQL): 并消除所有:POSTGRESQL仅选择至少有一个重复电话号码的重复帐户,sql,database,postgresql,Sql,Database,Postgresql,我想获得以下示例数据(POSTGRESQL): 并消除所有: 不重复的电子邮件条目(示例中uuid=6) 包含重复电子邮件的行,但所有电话号码都不同 (在示例中,uuid=7,8,9) 曼坦: 具有重复电子邮件条目且所有电话号码相等的行之一(在示例中,uuid=4,5) 具有重复电子邮件条目且至少两个电话号码相等的行之一(在示例中,uuid=1,2,3) 结果数据将是 email phone_number a@gmail.com 111
email phone_number
a@gmail.com 111
b@gmail.com 222
将
分组依据
子句与具有
select email, phone_number
from table t
group by email, phone_number
having count(*) > 1;
根据您的描述,您希望:
select email, max(phone_number)
from t
group by email
having count(*) > count(distinct phone_number) and
count(*) > 1;
到目前为止,您尝试了什么?我尝试过在电话和cpf相等时按电话和cpf进行过滤,但我损失了很多,因为当有2个重复帐户时,这一切正常,但如果有3个或更多,则不准确
select email, max(phone_number)
from t
group by email
having count(*) > count(distinct phone_number) and
count(*) > 1;