伙计们,
我有一个数据库表,如下所示:
uniqueId,asin,rank
1,abc,1
2,xyz,2
3,abc,1
4,xyz,2
5,opq,3如您所见,asin's (abc和xyz)被重复。因此,我希望我的查询,以避免他们完全和返回我只(opq)。
诚挚的问候
乌萨马
发布于 2018-06-25 05:04:39
我觉得你需要
select *
from yourtable a
where 1 = (
select count(*)
from yourtable
where a.asin = asin
)演示
发布于 2018-06-25 11:38:27
not exists应该具有最好的性能:
select t.*
from t
where not exists (select 1
from t t2
where t2.asin = t.asin and t2.id <> t.id
);为了提高性能,您需要(asin, id)上的索引。
https://stackoverflow.com/questions/51016562
复制相似问题