# mysql 两个字段相减时报错 BIGINT UNSIGNED value is out of range in

**URL:** <https://www.shiqidu.com/t/topic/416>\
**Category:** 开发调优\
**Tags:** MySQL\
**Created:** [May 3, 2018, 10:12am UTC](https://www.shiqidu.com/t/topic/416 "2018-05-03T10:12:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
**Post date:** [May 3, 2018, 10:12am UTC](https://www.shiqidu.com/t/topic/416/1 "2018-05-03T10:12:08Z")

</div>

当两个字段相减时，其中一个字段是 **unsigned** 无符号int 类型的时候回报错。

```sql
1525337724 - user.`reg_time` < 86400 * 3

```

报错如下

> BIGINT UNSIGNED value is out of range in

解决办法如下

使用 **cast** 函数把字段转为有符号的就行了。

```sql
1525337724 - cast(user.`reg_time` as signed) < 86400 * 3

```
