[英]MySQL Stored Procedure that select, check dates and insert
I am trying to create a stored procedure in MySQL. 我正在尝试在MySQL中创建一个存储过程。 I have never used one so I don't even know if it's possibile to do what I need.
我从来没有用过,所以我什至不知道是否有可能做我所需要的。
I have two tables : 我有两个表:
I need to select all the records from the first table that have 0 in the payment_status field, check if the date + payment_days exceeds the current date and insert a notification in the other table with the id of the operator. 我需要从第一个表中选择所有记录,其中payment_status字段中的记录为0,检查date + payment_days是否超过当前日期,并在另一个表中插入一个带有操作员ID的通知。
I hope you can help me, thanks. 希望您能帮助我,谢谢。
You can do this: 你可以这样做:
INSERT INTO notifications(text, id_operator)
SELECT 'notification text', id_operator
FROM jobs
WHERE payment_status = 0
AND CURRENT_DATE <= DATE(DATE_ADD(`date`, INTERVAL payment_days DAY));
Using INSERT INTO ... SELECT ...
you can select the results and insert them into another table. 使用
INSERT INTO ... SELECT ...
您可以选择结果并将其插入到另一个表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.