问题描述:
在写mysql语句时会经常用到两个时间戳相减来做查询条件,
SELECT
abs(answer_time-question_time)
FROM
...
因为字段类型为unsigned,所以当相减结果为负值时会报错,如下:
解决方法:
使用cast()修改字段类型为signed
SELECT
abs(cast(answer_time as signed)-cast(question_time as signed))
FROM
...
问题描述:
在写mysql语句时会经常用到两个时间戳相减来做查询条件,
SELECT
abs(answer_time-question_time)
FROM
...
因为字段类型为unsigned,所以当相减结果为负值时会报错,如下:
解决方法:
使用cast()修改字段类型为signed
SELECT
abs(cast(answer_time as signed)-cast(question_time as signed))
FROM
...