I have 2 tables, 1 contains the member data and the other is the transaction table. The members has different member IDs with different information on each IDs, but I only look up the member ID we consider as unique. Now the problem is, in the transactions table, it sometimes records the transaction under the other member's ID. Here's a table to further illustrate the situation:
TABLE = MEMBER_DATA
| MEMBER_ID | LINKED_ID | FNAME | LNAME | MEMBER_TYPE | TIER |
|---|---|---|---|---|---|
| 8888-1234 | X1234 | JOHN | SMITH | REGULAR | - |
| 7777-3333 | X1234 | JOHN | SMITH | - | GOLD |
| 8888-6666 | X0993 | HANNA | MONTANA | REGULAR | - |
| 7777-9999 | X0993 | HANNA | MONTANA | - | PLATINUM |
TABLE = TXN_TABLE
| MEMBER_ID | TXN_COUNT | AMOUNT |
|---|---|---|
| 8888-1234 | 1 | 3 |
| 8888-6666 | 2 | 4 |
| 7777-9999 | 2 | 2 |
RESULT:
| MEMBER_TYPE | MEMBER_ID | TXN_COUNT |
|---|---|---|
| REGULAR | 8888-1234 | 1 |
| REGULAR | 8888-6666 | 2 |
The member is assigned a MEMBER_ID known to them that starts with 8888, for us, there is another ID assigned to them for their other information that starts with 7777 (it's already that way when I got here so no possibility of change). The way we know they are the same person is because of the LINKED_ID. I only looked at MEMBER_IDs with MEMBER_TYPE = REGULAR to count the members. In the transactions table, it sometimes records the transaction to the member's other ID so I don't get an accurate count of transactions. The solution I came up with is to transform the MEMBER_DATA table to add their other MEMBER_ID and other information.
The question is, how now do I look up the MEMBER_ID2 if the TXN_TABLE MEMBER_ID doesn't match MEMBER_ID1?
TRANSFORMED TABLE:
TABLE = TRANSFORMED_MEMBER_DATA
| MEMBER_ID1 | LINKED_ID | FNAME | LNAME | MEMBER_TYPE | TIER | MEMBER_ID2 | TIER |
|---|---|---|---|---|---|---|---|
| 8888-1234 | X1234 | JOHN | SMITH | REGULAR | - | 7777-3333 | GOLD |
| 7777-3333 | X1234 | JOHN | SMITH | - | GOLD | - | - |
| 8888-6666 | X0993 | HANNA | MONTANA | REGULAR | - | 8888-6666 | PLATINUM |
| 7777-9999 | X0993 | HANNA | MONTANA | - | PLATINUM | - | - |
EXPECTED:
| MEMBER_TYPE | MEMBER_ID | TXN_COUNT | TIER |
|---|---|---|---|
| REGULAR | 8888-1234 | 1 | GOLD |
| REGULAR | 8888-6666 | 4 | PLATINUM |
Note: Relationship of TXN_TABLE and MEMBER_DATA is on column MEMBER_ID
