我想创建一个事件,当一lend_date
列正好经过 15 天时,它将执行一个INSERT
查询。
它将获取该行的 ID 和userid
,并将其插入到另一个表中。
例如:
id | userid | lend_date
---+----------+----------------------
1 | 1 | 2015-09-24 15:58:48
2 | 1 | 2015-09-21 08:22:48
而现在,正是2015-10-06 08:23:41
。所以事件应该得到第二行的ID,即2
,并将其插入到另一个表中。
我的事件查询应该是什么样的?
事件类型是RECURRING
。但我也不确定我应该每小时还是每天执行一次。最好的建议是什么?
这是比使用更好的方法Task Scheduler
吗?
我想插入获取的 ID 的另一个表是notification_table
,它将通知用户他/她有一个过期日期。
notification_table
看起来像这样:
id | userid | notificationid | notificationdate |
---+----------+------------------+----------------------+
1 | 1 | 1 | 2015-09-24 15:58:48 |
2 | 1 | 1 | 2015-09-21 08:22:48 |
我正在查看这个查询:
INSERT INTO notification_table (id, userid, notificationid, notificationdate)
SELECT id, userid, 1, NOW()
FROM first_table
WHERE lend_date + INTERVAL 15 DAY = NOW();