MySQL——定時函數+過程demo
阿新 • • 發佈:2018-06-04
語句 task sch time_zone pro format not in clas 設置
-- 函數 -- 設置好時區 set time_zone = ‘+8:00‘; -- 開啟事件調度器 set GLOBAL event_scheduler = 1; drop event if exists commission_zjdj_a_every_hours; # 設置分隔符為 ‘$$‘ DELIMITER $$ create event commission_zjdj_a_every_hours on schedule every 1 HOUR starts ‘2018-06-24 23:59:59‘ do begin CALL proc_zjdj_a_commission(); end $$ # 將語句分割符設置回 ‘;‘ DELIMITER ; -- 過程 ###獲取當天有效的資金對接A崗一次打包數據,保持當天一份 DROP PROCEDURE IF EXISTS proc_zjdj_a_commission; CREATE PROCEDURE proc_zjdj_a_commission () BEGIN DELETE FROM report_statistics_commission_inquiry WHERE type = 2 AND date_format(count_time, ‘%Y-%m‘) = date_format(now(), ‘%Y-%m‘); #一次打包--> 資金對接A崗 INSERT INTO `report_statistics_commission_inquiry` ( `user_id`, `order_code`, `execute_time`, `task_code`, `count_time`, `type`, `ext1`, `ext2`, `ext3` ) SELECT receive_id, order_code, finish_time, task_code, NOW(), 2, NULL, NULL, NULL FROM my_task WHERE `status` = 2 AND task_code = ‘T_YCDB_0004‘ #排除重復訂單 AND order_code NOT IN ( SELECT order_code FROM report_statistics_commission_inquiry WHERE type = 2 ) GROUP BY order_code; END;
MySQL——定時函數+過程demo