埃利奧特,
我沒有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不同的地方我想分離出現的地方。我對上面的代碼做了輕微的修改。 –