Say I have a system where users get tokens based on activity. For any token X, I'd like to know what other tokens users with token X has earned.
For example:
Table Tokens:
PrimaryKey = TokenID
TokenId | UserID | TokenName | TokenGiver
-----------------------------------------
111 | 1 | token_a| bob
222 | 1 | token_b| bob
333 | 1 | token_c| bob
444 | 2 | token_a| bob
555 | 2 | token_c| bob
666 | 3 | token_b| bob
777 | 4 | token_c| bob
888 | 5 | token_d| bob
Expected output, something close to this:
TokenName | count | AlsoEarned
------------------------------
token_a | 2 | [token_b: 1, token_c: 2]
token_b | 2 | [token_a: 1, token_c: 1]
token_c | 3 | [token_a: 2, token_b: 1]
token_d | 1 | []
Explanation: For token_a, UserID = 1 has earned it, as well as UserID = 2. UserID = 1 has also earned token_b and token_c and UserId = 2 has also earned token_c. Thus for token_a, we have [token_b: 1, token_c: 2]