Let's say I have two tables, T1 and T2, with exact same columns: ClientId
and ItemId
.
I want to calculate: for each ClientId
in T2, how many ItemId
s exist in T2 but not in T1.
Example:
T1
ClientId | ItemId |
---|---|
1 | 11 |
2 | 21 |
2 | 22 |
2 | 23 |
T2
ClientId | ItemId |
---|---|
2 | 22 |
2 | 23 |
2 | 24 |
2 | 25 |
3 | 31 |
Expected Output
ClientId | ItemIdCount |
---|---|
2 | 2 |
3 | 1 |
Explanation:
In T2
, for ClientId=2
, we have four ItemIds
: 22, 23, 24, 25. However, this same client ID in T1 has two of those values: 22, 23. Thus, the ItemIdCount
for this client ID is two.