I have 2 tables which are Account tbl and Customer tbl, the structure is like below:
Account tbl
Customer_ID Account_ID Parent_Account_ID
3780952 3780952 3780952
3780997 3780997 3780997
3781004 3781004 3780997
Customer tbl (Customer_Group have different value, but im only interest on Personal)
Customer_ID Customer_Group
3781004 Personal
3780997 Personal
3780952 Personal
The rule to determine PS/NonPS, Principle, Supp as per below:
**PS/NonPs**
Customer_ID equal to Parent_Account and Parent_Account is unique (not exist more than 1) then NonPs.
Customer_ID equal to Parent_Account and Parent_Account is non unique OR - Customer_ID is not equal to Parent_Account then PS
**Principle**
IF NonPS then Principle is Null
IF PS - If Customer_ID equal to Parent_Account then Principle is Y else N
**Supp**
IF NonPS then Supp is Null
IF PS - If Customer_ID not equal to Parent_Account then supp is Y else N
The final output should be like this
Customer_ID Account_ID Parent_Account_ID PS/NonPS Principle Supp
3780952 3780952 3780952 NonPS Null Null
3780997 3780997 3780997 PS Y N
3781004 3781004 3780997 PS N Y
I alredy tried many times but still cant get the output..anyone can help ?