Mysql ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in..的解决方法

时间:2022-06-01 16:03:13

问题描述
在写mysql语句时会经常用到两个时间戳相减来做查询条件,

SELECT
abs(answer_time-question_time)
FROM
...

因为字段类型为unsigned,所以当相减结果为负值时会报错,如下:
Mysql ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in..的解决方法
解决方法:
使用cast()修改字段类型为signed

SELECT
abs(cast(answer_time as signed)-cast(question_time as signed))
FROM
...