I have a table:
client_id | Date | Resolution |
---|---|---|
1 | 2022-10-15 | CANCELLED |
2 | 2022-10-25 | CANCELLED |
3 | 2022-10-16 | CANCELLED |
3 | 2022-10-17 | REJECTED |
4 | 2022-10-08 | CANCELLED |
4 | 2022-10-20 | APPROVED |
5 | 2022-10-03 | CANCELLED |
5 | 2022-10-04 | APPROVED |
Desired results:
client_id |
---|
1 |
2 |
4 |
I need to get all customers IDs who have been CANCELLED and within five days didn’t have REJECTED or APPROVED the application. How can I achieve that?
2
Answers
The solution:
Explanation: We search for all
t1
records that were cancelled and do not have a match int2
that was either rejected or approved, so, the join condition searches for items with such pairs, defaulting to t2.* being null if there is no such pair fort1
and then applying awhere
filter that leaves only thet1
records having no such pairs in the result.