I am trying to create a stored procedure in 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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.