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

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

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
posted @ 2024-05-11 14:18  pine007  阅读(49)  评论(0编辑  收藏  举报