Query Help - Need to generate group ids
887111Sep 8 2011 — edited Sep 9 2011Hi,
I need help to write a sql to generate group ids as shown below
FIRST_NAME LAST_NAME DOB ZIP_CODE EMAIL Ruletype Group_id
Michelle Parker 1/1/1900 92675 nonexistence@nonexistent.com DUPR1 1
Michelle Parker 1/1/1900 92675 nonexistence@nonexistent.com DUPR1 1
John Hastings 97301 nonexistence@nonexistent.com DUPR2 2
John Hastings 8/7/1977 nonexistence@nonexistent.com DUPR2 2
Here we have multiple rules to generate the group ids.
Say if ruletype = DUPR1 then First Name, last name, Dob and Zip code is compared and if the match is found then group id is generated as 1
for ruletype = DUPR2 First name, last name and email address are compared and if a match is found then group id should be 2
I used the below query to generate the group id's
Select row_id,fst_name,last_name,dob,zipcode,email_Addr,dup_row_id,group_id,
case when ruletype = 'DUPR1' then dense_Rank() over (partition by '' order by fst_name,last_name,dob,zipcode,ruletype)
when ruletype = 'DUPR2' then dense_Rank() over (partition by '' order by fst_name,last_name,email_Addr,ruletype)
end groupid from stg_drms_duplicate_Tab order by ruletype
When the query returns data, the group ids are not continuous as shown below
FIRST_NAME LAST_NAME DOB ZIP_CODE EMAIL Ruletype Group_id
Michelle Parker 1/1/1900 92675 nonexistence@nonexistent.com DUPR1 1
Michelle Parker 1/1/1900 92675 nonexistence@nonexistent.com DUPR1 1
John Hastings 97301 nonexistence@nonexistent.com DUPR2 2
John Hastings 8/7/1977 nonexistence@nonexistent.com DUPR2 2
WADE COLE 9/25/1955 nonexistence@nonexistent.com DUPR2 4
WADE COLE 9/25/1955 nonexistence@nonexistent.com DUPR2 4
please help me to solve this problem