I have table with userID, FY, clientID
I want a SQL statement that gives me the latest interaction count with the client by the user.
Example: In the below table I have User 1 who had interactions with client "10001" in 2024, 23, 22, after that in 2021 he had interaction with other client called "10002" and in the past in 2020, he had interaction with old client "10001".
But, I want to see the latest and current interactions User is having with the clients.
So, it should be 3 for the userID 1
UserID | FY | ClientID |
---|---|---|
1 | 2024 | 10001 |
1 | 2023 | 10001 |
1 | 2022 | 10001 |
1 | 2021 | 10002 |
2 | 2024 | 10003 |
2 | 2023 | 10003 |
3 | 2024 | 10001 |
1 | 2020 | 10001 |
2 | 2016 | 10003 |
Results I am looking for are:
UserID | FY | ClientID | CountOfRecentInteractions |
---|---|---|---|
1 | 2024 | 10001 | 3 |
2 | 2024 | 10003 | 2 |
3 | 2024 | 10001 | 1 |
Is this possible with SQL query?