Hello, I have a database - mysql and would like to decrease a value in an entire column

Asked

Viewed 125 times

-1

I’d like to use the command update to decrease an hour in the values you already have in the table of several values in the whole column.

EX:

Nome da Coluna         Gostaria da coluna assim
     HORA                      HORA

    13:45                     12:45
    15:00                     14:00    
    17:00                     16:00

The value in the column eh that same 13:00 would like to decrease 1hr in the entire column ... with the update command.

  • Assuming your field is team-like, try: UPDATE sua_tabela SET seu_campo = SUBTIME(seu_campo, '01:00:00');

1 answer

1

There are several ways to solve this, one of them is using the function SUBDATE() It serves to decrease any kind of information from a field DATETIME.

Example:

UPDATE sua_tabela SET
    hora = SUBDATE(hora, INTERVAL 1 HOUR);

Follow an example on Sqlfiddle.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.