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

今天在做一个功能的时候,用到两个时间戳相减来做查询条件,由于其两个字段都是unsigned的,并两个的大小是不一样。所以直接相减查询的时候,

就出现ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in..的错误,因为结果可能会出现负数。。。。

过后查资料,发现可以通过下面的方法来解决:

[sql]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mysql> select lastvisit, lastactivity from pre_common_member_status limit 1;  
  2. +------------+--------------+  
  3. | lastvisit  | lastactivity |  
  4. +------------+--------------+  
  5. | 1199200260 |   1198336989 |  
  6. +------------+--------------+  
  7. 1 row in set (0.01 sec)  
  8.   
  9. mysql> select lastvisit-lastactivity from pre_common_member_status limit 1;  
  10. +------------------------+  
  11. | lastvisit-lastactivity |  
  12. +------------------------+  
  13. |                 863271 |  
  14. +------------------------+  
  15. 1 row in set (0.05 sec)  
  16.   
  17. mysql> select abs(lastvisit-lastactivity) from pre_common_member_status limit 1;  
  18.   
  19. +-----------------------------+  
  20. abs(lastvisit-lastactivity) |  
  21. +-----------------------------+  
  22. |                      863271 |  
  23. +-----------------------------+  
  24. 1 row in set (0.03 sec)  
  25.   
  26. mysql> select lastactivity-lastvisit from pre_common_member_status limit 1;  
  27. ERROR 1690 (22003): BIGINT UNSIGNED value is out of range in '(`discuz`.`pre_c  
  28. ommon_member_status`.`lastactivity` - `discuz`.`pre_common_member_status`.`las  
  29. tvisit`)'  
  30. mysql> select cast(lastactivity as signed)-cast(lastvisit as signed) from pre_co  
  31. mmon_member_status limit 1;  
  32. +--------------------------------------------------------+  
  33. cast(lastactivity as signed)-cast(lastvisit as signed) |  
  34. +--------------------------------------------------------+  
  35. |                                                -863271 |  
  36. +--------------------------------------------------------+  
  37. 1 row in set (0.02 sec)  
  38.   
  39. mysql> select abs(cast(lastactivity as signed)-cast(lastvisit as signed)) from p  
  40. re_common_member_status limit 1;  
  41. +-------------------------------------------------------------+  
  42. abs(cast(lastactivity as signed)-cast(lastvisit as signed)) |  
  43. +-------------------------------------------------------------+  
  44. |                                                      863271 |  
  45. +-------------------------------------------------------------+  
  46. 1 row in set (0.00 sec)  
  47.   
  48. mysql>  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值