0
불행히도 많은 중복 레코드가있는 차원 테이블이 있습니다. 스크린 샷을 참조하십시오. 차원 테이블에서 중복 된 결과로 테이블 이동 및 교체
나는 수천 명의 사용자와 중복을 참조하는 5 개의 테이블이 있습니다. "bad"가 포함 된 레코드를 삭제하고 싶습니다 UserID
s. 나는 5 개의 종속성을 살펴보고 "good"(빨간색 동그라미)로 bad UserId
을 업데이트하려고합니다.
이 방법에 대한 좋은 접근 방법은 무엇입니까? 여기에 위의 스크린 샷을 얻기 위해 무슨 짓을했는지
...
SELECT UserID
,userIds.FirstName
,userIds.LastName
,dupTable.Email
,dupTable.Username
,dupTable.DupCount
FROM dbo.DimUsers AS userIds
LEFT OUTER JOIN
(SELECT FirstName
,LastName
,Email
,UserName
,DupCount
FROM
(SELECT FirstName
,LastName
,UserName
,Email
,COUNT(*) AS DupCount -- we're finding duplications by matches on FirstName,
-- last name, UserName AND Email. All four fields must match
-- to find a dupe. More confidence from this.
FROM dbo.DimUsers
GROUP BY FirstName
,LastName
,UserName
,Email
HAVING COUNT(*) > 1) AS userTable -- any count more than 1 is a dupe
WHERE LastName NOT LIKE 'NULL' -- exclude entries with literally NULL names
AND FirstName NOT LIKE 'NULL'
)AS dupTable
ON dupTable.FirstName = userIds.FirstName -- to get the userIds of dupes, we LEFT JOIN the original table
AND dupTable.LastName = userIds.LastName -- on four fields to increase our confidence
AND dupTable.Email = userIds.Email
AND dupTable.Username = userIds.Username
WHERE DupCount IS NOT NULL -- ignore NULL dupcounts, these are not dupes