处理unsigned相减错误(BIGINT UNSIGNED value is out of range)

mysql 当两个字段想减时,如果其中一个或两个字段的类型的unsigned无签名类型,如果想减的值小于0则会报错(BIGINT UNSIGNED value is out of range)

测试:

select cast(1 as unsigned)-2

select 0-cast(1 as unsigned)

解决办法:

一、修改字段类型

二、使用cast函数转字段为signed类型

select cast(1 as signed)-2

原文地址:https://www.cnblogs.com/tujia/p/5916202.html