Request update error

I just confuse in this query and I don’t know how to solve it, if you have any ideas about this, please help me or help, definitely appreciated

I have a table structure like this and the test column contains 3 values

enter image description here

UPDATE `test` SET test = test -3

when I execute this query, the result will be shown as follows

enter image description here

UPDATE `test` SET test = test -4

But when I execute this query, the result will not be correctly saved in the test column, like this

enter image description here

0 result is required or I do not need to subtract value

+3
source share
3 answers

-, BIGINT UNSIGNED. , BIGINT ( NULL NOT NULL ):

ALTER TABLE test
  MODIFY COLUMN test BIGINT;

UPDATE. 0 -4 , GREATEST(), :

UPDATE `test` SET test = GREATEST(CAST(test AS SIGNED) - 4,0)
+2

, , , bigint .

, bigint

. : -9223372036854775808 9223372036854775807. 0 18446744073709551615.

- 3 (4 0 xxx15, )

, , (), .

ALTER TABLE test MODIFY COLUMN test BIGINT SIGNED;

UPDATE

BIGINT UNSIGNED , , , 0, :

UPDATE test
SET test = CASE WHEN test >= value THEN test-value ELSE 0 END 

, , , , , 0, .

+1

According to this question: MySQL: bigint Vs int

The maximum maximum value is 18,446,744,073,709,551,615

You wrap to the highest value when you subtract from 0, since your bigint has no sign.

0
source

All Articles