I looked through the previous topics that may have been related to this and didn't find anything pertaining to what my questions is.
My question is can you update a datetime value in MySql based on the previously updated row? To better explain what I'm wondering here is a pseudo-SQL statement to explain what I'm looking for (no, this is not real SQL):
update my_datetime set my_datetime = previously_updated_time + 30 minutes;
so the times would go something like this in the update:
1970-01-01 00:00:00
1970-01-01 00:30:00
1970-01-02 01:00:00
etc...
but accomplishing this all based on the first row updated being the 1970-01-01 00:00:00 value. If it can't be done, I understand but I wanted to see if this would be possible.
If your primary key is INT
you can do this:
UPDATE mytable SET mytable.datetime = mytable.datetime + INTERVAL 30 * mytable.id MINUTE
Edit: This works without using primary key:
SET @lowest = ( SELECT MIN( datetime ) FROM mytable );
UPDATE mytable
SET mytable.datetime = (@lowest:=@lowest + INTERVAL 30 MINUTE)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments