我已将事件记录创建为root
用户,而GLOBAL event_scheduler
也是ON
我的事件过程查询是:
DELIMITER $$
CREATE
EVENT `near_end_warranty`
ON SCHEDULE EVERY 1 HOUR
DO BEGIN
DECLARE numrow int;
SELECT COUNT(id) FROM equipments WHERE TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)<5 AND TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)>0 INTO numrow;
IF numrow>0 THEN
INSERT INTO notifications (eq_id,start_date,end_date,name,type,message,created_by,modified_by,created_on,modified_on)
SELECT eq_id,warranty_start_date,warranty_end_date,'warranty','ending soon','warranty ends soon for','System','System',NOW(),NOW()
FROM equipments WHERE TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)<5 AND TIMESTAMPDIFF(WEEK,NOW(),warranty_end_date)>0;
END IF;
END $$
DELIMITER ;
我的活动状态是:
Db:db_medisup
Name:near_end_warranty
Definer:root@localhost
Time zone:SYSTEM
Type:RECURRING
Execute at:NULL
Interval value:1
Interval field:HOUR
Starts:2015-05-08 07:11:09
Ends:NULL
Status:ENABLED
Originator:1
character_set_client:utf8
collation_connection:utf8_general_ci
Database Collation:latin1_swedish_ci
我正在尝试根据条件从设备表中获取多行,并按小时插入到通知表中。我在07:11创建了此事件,其9:52已经创建并且未插入任何行进行通知表yet.warranty_end日期:2015-05-20关于两排设备表,今天的日期是2015-05-08,所以必须在通知表中添加两行。这里可能出现什么问题?
答案 0 :(得分:0)
我实际上发现了确切的问题,在表的字段名称和查询中有轻微的错误,我现在已经解决了它,一切都运行得很好。