I have two tables in a CRM application that I am trying to build.
Contacts | id | Name | ContactFrequency (in days) | |----|------|------------------| | 1 |John | 7 | |2|Pete|30|
Events |id|Contacts_id|Description|Unix_Timestamp| |--|-----------|-------|-------| |1|1|Sent John an email|1609667504| |2|1|Gave John a call|1609645455| |1|2|Sent Pete a letter in the mail|1609666755|
The "ContactFrequency" is how often I should call that client to stay in touch. Each entry in Events is a call log with a UNIX timestamp. I want to generate a list of clients who need to be called in the next X number of days (or whose next contacts have already passed and are overdue), such as the following (timestamps are completely arbitrary in my examples):
| Client | Next Contact Due on (Timestamp)(Ordered by this column) |
|---|---|
| Pete | 1609645352 |
| John | 1609634342 |
How would I do this with a query? I can't wrap my head around it.
https://stackoverflow.com/questions/66451083/how-do-i-do-a-mysql-join-on-conditions-based-on-mathematical-operations-across-t March 03, 2021 at 01:05PM
没有评论:
发表评论