Update value based on the previous updated value mysql

Cameeob2003

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.

vinz

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate updated value based on a column

From Dev

Update Ignore if the updated value will be negative

From Dev

MySQL CASE based on previous CASE value

From Dev

mysql update column then select updated value

From Dev

SQL UPDATE: previous updated columns value in further columns

From Dev

mysql query based on value of previous row

From Dev

Update based on previous value SQL SERVER 2005

From Dev

MySQL - Update table and set column value equal to different of current row value minus previous row value

From Dev

MySQL - Update rows where value in column is the same as previous row

From Dev

Update minimum values based on another value - MySql

From Dev

Mysql: change the column value based on column's previous value

From Dev

Create sequence based on previous value

From Dev

How To Update The Date Based On Previous Record Value

From Dev

MYSQL Trigger update not working as expected when value is updated

From Dev

MySQL: How to efficiently bulk upsert rows, based on previous value?

From Dev

How To Update The Date Based On Previous Record Value

From Dev

MySql increment or not based on a previous value

From Dev

MySQL update trigger error; setting a value in an updated record

From Dev

MySQL CASE based on previous CASE value

From Dev

mysql - If I update one row, all the other rows (including updated row) return updated value

From Dev

mysql query based on value of previous row

From Dev

MySQL Update Value of column Based on DATE

From Dev

Remove the previous value and update the array

From Dev

Groupby based on value in previous row

From Dev

Update column value and return updated value in same query MySQL, Java

From Dev

Mysql: change the column value based on column's previous value

From Dev

SQL Server update value if previous value is not null

From Dev

calculate value based on value from previous value

From Dev

selection based on previous row value

Related Related

  1. 1

    Calculate updated value based on a column

  2. 2

    Update Ignore if the updated value will be negative

  3. 3

    MySQL CASE based on previous CASE value

  4. 4

    mysql update column then select updated value

  5. 5

    SQL UPDATE: previous updated columns value in further columns

  6. 6

    mysql query based on value of previous row

  7. 7

    Update based on previous value SQL SERVER 2005

  8. 8

    MySQL - Update table and set column value equal to different of current row value minus previous row value

  9. 9

    MySQL - Update rows where value in column is the same as previous row

  10. 10

    Update minimum values based on another value - MySql

  11. 11

    Mysql: change the column value based on column's previous value

  12. 12

    Create sequence based on previous value

  13. 13

    How To Update The Date Based On Previous Record Value

  14. 14

    MYSQL Trigger update not working as expected when value is updated

  15. 15

    MySQL: How to efficiently bulk upsert rows, based on previous value?

  16. 16

    How To Update The Date Based On Previous Record Value

  17. 17

    MySql increment or not based on a previous value

  18. 18

    MySQL update trigger error; setting a value in an updated record

  19. 19

    MySQL CASE based on previous CASE value

  20. 20

    mysql - If I update one row, all the other rows (including updated row) return updated value

  21. 21

    mysql query based on value of previous row

  22. 22

    MySQL Update Value of column Based on DATE

  23. 23

    Remove the previous value and update the array

  24. 24

    Groupby based on value in previous row

  25. 25

    Update column value and return updated value in same query MySQL, Java

  26. 26

    Mysql: change the column value based on column's previous value

  27. 27

    SQL Server update value if previous value is not null

  28. 28

    calculate value based on value from previous value

  29. 29

    selection based on previous row value

HotTag

Archive