我想获取此示例数据(POSTGRESQL):
uuid email phone_number
1 a@gmail.com 111
2 a@gmail.com 111
3 a@gmail.com 112
4 b@gmail.com 222
5 b@gmail.com 222
6 c@gmail.com 333
7 d@gmail.com 444
8 d@gmail.com 445
9 d@gmail.com 446
消除所有:
并且保持:
结果数据为
email phone_number
a@gmail.com 111
b@gmail.com 222
答案 0 :(得分:1)
将group by
子句与having
select email, phone_number
from table t
group by email, phone_number
having count(*) > 1;
答案 1 :(得分:0)
根据您的描述,您想要:
select email, max(phone_number)
from t
group by email
having count(*) > count(distinct phone_number) and
count(*) > 1;