sql - Partition by using multiple case statements -
i attempting dedupe records in database using partition clause query run in order dedupe. ranks records populated , keeps highest ranked record.
ctedupes ( -- -- partition based on contact.owner , email select row_number() over(partition contactowner, email order -- ranking populated field case when otherstreet not null 1 else 0 end + case when othercity not null 1 else 0 end ) rnd, * scontact (contact_owner_name__c not null , contact_owner_name__c<>'') , (email not null , email<>'') ) --rank data , place new table created select * contact_case1 ctedupes rnd=1;
i wanted know if possible partition using case. example partitioning contactowner , email. when contactowner null want partition contactofficer instead. can create case statements or not possible since ranking altered in someway.
you can use case
, think coalesce()
simpler in case:
select row_number() on (partition coalesce(contactowner, contactofficer), email . . .
if want contacts , officers same name counted separately, do:
select row_number() on (partition (case when contactowner null 1 else 2 end), contactowner, (case when contactowner null contactofficer end), email . . .
Comments
Post a Comment