1

I need to change the value of a specific field/column of multiple records and between specific dates, in a MySQL table. Using the MySQL workbench v5.2. So for example I need to check if the value is over x, between two specific dates. If it is over x, then I need to make it = y. I was trying the below statement which doesn't work. It's giving me an error on the WHERE clause.

UPDATE `mydb`.`mytable` WHERE `Time_Stamp`
BETWEEN '2014-12-31 00:00:00'
    AND '2014-11-31 06:00:00'
IF `my_Column` > x Then
    `my_Column` = y
End IF;

Even if it does accept the WHERE clause, I'm not sure the IF statement will work following on from that. As you can see I'm a learner. So any help would be much appreciated.

1 Answer 1

1

Try this:

UPDATE mydb.mytable 
SET my_Column = CASE WHEN my_Column > x THEN y ELSE x END
WHERE Time_Stamp BETWEEN '2014-12-31 00:00:00' AND '2014-11-31 06:00:00'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.