I have a table_A with data extracted from service cloud (salesforce) about customers (name, email, customer_nr, etc), but for the same email I have more than one entry. This happens due to different reasons, but I want to select only the row that follows a certain rule, because I can only have one email per person.
Table_A:
CustomerType | First_Name | Last_Name | Owner_FirstName | Owner_LastName | |
---|---|---|---|---|---|
testA@email.com | CustomerServiceAdd | NULL | NULL | Patricia | Portela |
testA@email.com | RegisteredSubscriber | John | Smith | User | SCCIntegration |
So basically when I group by the email and having count(*)>1, it needs to follows these rules:
I want that when there is more than one entry for the same email, it selects the row where CONCAT([Owner.FirstName],[Owner.LastName])='UserSCCIntegration'
When for the same email, there's more than one row where CONCAT([Owner.FirstName],[Owner.LastName])='UserSCCIntegration', then should be selected the row where SFCC_Customer_Number__pc (this column was not selected for table_A, but it exists in my datatable) is not NULL.
I tried using a CASE WHEN but didn't manage to produce any result, so I am wondering how should the query be created and if using CASE WHEN clause is the right way to go.