我有两个表,events
和event_logs
。
events
表存储定期事件的理论数据,而event_log
存储特定日期时间的特定信息。
+-----+---------------------------+----------+-------------------------------------------------------------------------------------------+
| id | start_at | place_id | recurring_schedule |
+-----+---------------------------+----------+-------------------------------------------------------------------------------------------+
| 358 | 2015-01-23 20:00:00 +0000 | 412 | {"validations":{"day":[2]},"rule_type":"IceCube::WeeklyRule","interval":1,"week_start":0} |
| 359 | 2016-01-22 19:30:00 +1100 | 414 | {"validations":{"day":[1]},"rule_type":"IceCube::WeeklyRule","interval":1,"week_start":0} |
| 360 | 2016-02-01 19:00:00 +1100 | 415 | {"validations":{"day":[4]},"rule_type":"IceCube::WeeklyRule","interval":1,"week_start":0} |
| 361 | 2016-02-01 20:00:00 +0000 | 416 | {"validations":{"day":[4]},"rule_type":"IceCube::WeeklyRule","interval":1,"week_start":0} |
| 362 | 2014-02-13 20:00:00 +0000 | 417 | {"validations":{"day":[2]},"rule_type":"IceCube::WeeklyRule","interval":1,"week_start":0} |
+-----+---------------------------+----------+-------------------------------------------------------------------------------------------+
+-------+----------+----------+---------------------------+------------+
| id | place_id | event_id | start_at | state |
+-------+----------+----------+---------------------------+------------+
| 20600 | 58 | 35 | 2017-01-24 19:30:00 +0000 | completed |
| 13236 | 105 | 94 | 2015-09-07 20:00:00 +0100 | pending |
| 21388 | 311 | 269 | 2017-04-09 18:30:00 +0100 | failed |
| 25265 | 23 | 45 | 2017-10-22 20:00:00 +0100 | incomplete |
| 25538 | 283 | 242 | 2017-11-07 19:30:00 +1100 | failed |
+-------+----------+----------+---------------------------+------------+
问题是将重复数据与实际出现进行协调,EventLog上的数据不存在,但为了速度和必要性,我想创建某种聚合视图,例如scheduled_events
(其外观和行为类似event_log)但它结合了理论上的未来事件和他们的开始时间&实际发生的EventLogs的日期(当它们存在时)。但如果有人提出一些建议,我不确定如何做到这一点。
谢谢,