埃利奥特,
我没有SQL的拷贝在我的面前,现在,所以如果我的道歉语法没有发现上。
我会通过寻找重复的开始:
select
x.isin
,count(*)
from edm_security_entity_map as x
group by x.isin
having count(*) > 1
然后加入该回全表以找到那些重复来自:
;with DuplicateList as
(
select
x.isin
--,count(*) -- not used elsewhere
from edm_security_entity_map as x
group by x.isin
having count(*) > 1
)
select
map.isin
,map.entity_id
from edm_security_entity_map as map
inner join DuplicateList as dup
on dup.isin = map.isin;
HTH, 迈克尔
所以你是说,如果isin-1对于entity-1和entity-2都有一行是一个错误,但是inin-3,比如链接到两个分隔行中的entity-3是好的?丑陋的,但可读的解决方案,即预先挂起另一CTE在前面的解决方案
;with UniqueValues as
(select distinct
y.isin
,y.entity_id
from edm_security_entity_map as y
)
,DuplicateList as
(
select
x.isin
--,count(*) -- not used elsewhere
from UniqueValues as x
group by x.isin
having count(*) > 1
)
select
map.isin
,map.entity_id
from edm_security_entity_map as map -- or from UniqueValues, depening on your objective.
inner join DuplicateList as dup
on dup.isin = map.isin;
,有具有附加GROUP更好的解决方案通过在最终的查询子句。如果这是进入生产,我会推荐。或者如果你的表有一个bajillion行。如果你只需要做一些分析,我希望以上就足够了。
谢谢Michael;差不多了。这也返回多个实体ID是相同的链接到ISIN,这是正常的。这是实体ID不同的地方我想分离出现的地方。我对上面的代码做了轻微的修改。 –