我有下面提到的桌子:
Source Value e_mail count ID
RT-121 124566 aft.12@hotmail.com PR12S P-1
RT-122 124887 efyyhd@hotmail.com P-2
RT-123 124887 efyyhd@hotmail.com PR12S P-3
RT-124 484566 aft.19@hotmail.com P-7
RT-125 484566 aft.19@hotmail.com PR12S P-8
RT-126 124566 aft.12@hotmail.com PR12S P-1 我想编写一个查询,在Value和e_mail相同并且Count是Null或空白有不同ID的情况下给出输出。
所需产出:
Source Value e_mail count ID
RT-122 124887 efyyhd@hotmail.com P-2
RT-123 124887 efyyhd@hotmail.com PR12S P-3
RT-124 484566 aft.19@hotmail.com P-7
RT-125 484566 aft.19@hotmail.com PR12S P-8发布于 2018-07-23 15:01:10
一种方法是使用exists
select t.*
from t
where exists (select 1
from t t2
where t2.value = t.value and
t2.e_mail = t.e_mail and
(t2.count <> '' xor t.count <> '') and
t2.source <> t.source
);使用(value, e_mail, source)上的索引,这可能是最快的方法。
https://stackoverflow.com/questions/51481832
复制相似问题