Here's my query
CREATE EVENT saturday
ON SCHEDULE
EVERY 6 DAY
STARTS (TIMESTAMP(CURRENT_DATE) + INTERVAL 1 DAY)
DO UPDATE `AttrInfo`.`attrID` SET `4` = '2000';
Idea behind is that it will double the value for Saturday, and then I need to find a way for it to change the value back to 1000 when Sunday starts.
image from the table
AttrInfo = table
attr1 = column
4 = row
value = 2000
Related
I have one table where every worker chose the meal that he wants for each day of the week (kitchen_wishes), and contains an ID column, and columns Monday, Tuesday, etc. The selection is stored as an integer value.
and another table where the selection for THAT day is copied from the first table (food_for_today). This table contains one ID column (in same order as the first table) and another column - what_to_eat. It is pretty straight forward.
I try to create a daily event in the SQL database which would move the values for that day from the first table to the second, every day at 9:00, but I have various issues, generally with copying values from one table to another depending on the day.
Here is my code:
```
CREATE EVENT update_kitchen_wishes
ON SCHEDULE
EVERY 1 DAY
STARTS '2020-09-02 09:00:00' ON COMPLETION PRESERVE ENABLE
DO
SET #today = WEEKDAY(CURDATE()+1);
INSERT INTO food_for_today (what_to_eat)
SELECT
CASE
WHEN #today = 1 THEN Monday
WHEN #today = 2 THEN Tuesday
WHEN #today = 3 THEN Wednesday
WHEN #today = 4 THEN Thursday
WHEN #today = 5 THEN Friday
WHEN #today = 6 THEN Saturday
WHEN #today = 7 THEN Sunday
END
FROM kitchen_wishes;
I have a table ‘comenzi’, each order has a value for in progress, and another for ready and data. Each order when it is created has the values for in progress and ready equal to 0. I want to update the values for in progress and ready with 1 min ,after 20 min, then 30 min after the order has been done, the value from data that has the form 2020-05-25 09:41:00.
I need a way to update these values, a function or an event in database.
I was dealing with something using events just yesterday on a pet project. You could use a similar approach.
This code uses a creation column, which is just a TIMESTAMP column with a default value of CURRENT_TIMESTAMP (because I don't have your data) and a value column (default value 0), which goes from 1 - 2 (you can modify this code to suit your needs).
The SET value uses CASEs to check how long ago the order was created. Then it updates the value accordingly. You can change up the event to update whichever columns / time cases you'll need.
CREATE DEFINER =`root`#`localhost` EVENT `progressEvent`
ON SCHEDULE EVERY 1 MINUTE STARTS '2020-09-01 00:00:00'
ON COMPLETION PRESERVE ENABLE DO UPDATE comenzi
SET `value` = (
CASE WHEN (creation < (CURRENT_TIMESTAMP - INTERVAL 30 MINUTE))
THEN 2
CASE WHEN (creation < (CURRENT_TIMESTAMP - INTERVAL 20 MINUTE))
THEN 1
END)
WHERE value < 2
Edit: Changed it up so that it checks every minute and only 20/ 30 minutes.
I have sent_date and status in my table. I wanted to update the status automatically after 10 days.
Suppose sent_date is 24/03/2018 and status is Sent/Received. So on 04/04/2018, the status should update to Aborted automatically.
I know I have to use Date_Add but for testing purpose I am making use of Date_Sub.
What I tried:
CREATE EVENT rot ON SCHEDULE EVERY 1 day DO
update barter_proposals
set proposal_status="Aborted"
WHERE sent_date=DATE_SUB(CURDATE(), INTERVAL 1 day )
AND proposal_status = "Sent/Received"
So here,CURDATE takes the date of the system(24/03/2018),and it is updating the 23/03/2018 status to Aborted..This works fine.
CREATE EVENT rot ON SCHEDULE EVERY 1 day DO
update barter_proposals
set proposal_status="Aborted"
WHERE sent_date=DATE_SUB(sent_date, INTERVAL 1 day )
AND proposal_status = "Sent/Received"
sent_date in the table can be anything. So for this, it is not working properly. What changes are required so that the status can be automatically update after 10 days?
CREATE EVENT rot ON SCHEDULE EVERY 1 day DO
update barter_proposals
set proposal_status="Aborted"
WHERE sent_date=DATE(CURDATE()-10)
AND proposal_status = "Sent/Received"
I am new to SQL and I want to update the Amount in the amount field. For example in every month in 3 months I want to add 100 to THE 500 in the amount field in the database. And when the 3rd month comes It will automatically transfer the data to another table
This is the the code I have done so far, but its not working
CREATE EVENT myevent
ON SCHEDULE EVERY 1 MINUTE
STARTS CURRENT_TIMESTAMP
ENDS CURRENT_TIMESTAMP + INTERVAL 2 MINUTE
DO
UPDATE message
SET amount*3
WHERE date = NOW();
Try to change the update command into:
UPDATE Message
SET amount = amount + 100
WHERE DATEDIFF(CURDATE(), date) >=value
I have a table reservation containing starttime,endtime,status. i wanted to create an event scheduler which checks whether the current time is greater than endtime . if it is greater then it sets the status to 0.
but i want that scheduler to run everyday from 6 am to 6pm at 5 minutes interval for forever. so far i have written a code
CREATE EVENT rescancel
ON SCHEDULE EVERY 5 MINUTE
STARTS 06:00:00
ENDS 18:00:00
DO
UPDATE reservation SET status = 0 WHERE CURTIME() > endtime
how can i make sure that this event runs everyday? so far from what i have read from different websites , this code runs for every 5 minutes from 6 am to 6pm only for that day when event is created. am i wrong? i am new to mysql triggers and events.
I use something similar to check days and times, so you could use:
DELIMITER ||
CREATE EVENT rescancel
ON SCHEDULE
EVERY 5 MINUTE
STARTS NOW()
ON COMPLETION PRESERVE
COMMENT ''
DO
BEGIN
IF CURRENT_TIME BETWEEN '06:00:00' AND '18:00:00' THEN
UPDATE reservation SET status = 0 WHERE CURTIME() > endtime;
END IF;
END ||
DELIMITER ;
Test the current time in the query:
CREATE EVENT rescancel
ON SCHEDULE EVERY 5 MINUTE
DO
UPDATE reservation
SET status = 0
WHERE HOUR(CURTIME()) BETWEEN 6 AND 17
AND CURTIME() > endtime