BIGINT UNSIGNED value is out of range in..的解决方法
Posted on 2021-08-13 16:10 jiaoqing。 阅读(499) 评论(0) 编辑 收藏 举报今天在做一个功能的时候,用到两个时间戳相减来做查询条件,由于其两个字段都是unsigned的,并两个的大小是不一样。所以直接相减查询的时候,
就出现ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in..的错误,因为结果可能会出现负数。。。。
过后查资料,发现可以通过下面的方法来解决:
mysql> select lastvisit, lastactivity from pre_common_member_status limit 1; +------------+--------------+ | lastvisit | lastactivity | +------------+--------------+ | 1199200260 | 1198336989 | +------------+--------------+ 1 row in set (0.01 sec) mysql> select lastvisit-lastactivity from pre_common_member_status limit 1; +------------------------+ | lastvisit-lastactivity | +------------------------+ | 863271 | +------------------------+ 1 row in set (0.05 sec) mysql> select abs(lastvisit-lastactivity) from pre_common_member_status limit 1; +-----------------------------+ | abs(lastvisit-lastactivity) | +-----------------------------+ | 863271 | +-----------------------------+ 1 row in set (0.03 sec) mysql> select lastactivity-lastvisit from pre_common_member_status limit 1; ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`discuz`.`pre_c ommon_member_status`.`lastactivity` - `discuz`.`pre_common_member_status`.`las tvisit`)' mysql> select cast(lastactivity as signed)-cast(lastvisit as signed) from pre_co mmon_member_status limit 1; +--------------------------------------------------------+ | cast(lastactivity as signed)-cast(lastvisit as signed) | +--------------------------------------------------------+ | -863271 | +--------------------------------------------------------+ 1 row in set (0.02 sec) mysql> select abs(cast(lastactivity as signed)-cast(lastvisit as signed)) from p re_common_member_status limit 1; +-------------------------------------------------------------+ | abs(cast(lastactivity as signed)-cast(lastvisit as signed)) | +-------------------------------------------------------------+ | 863271 | +-------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>
分类:
MySQL
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?