在项目中做数据统计的时候需要用到几个字段相减得到想要的值,但是因为字段都是无符号,相减出现mysql 错误 BINGINT UNSIGNED VALUE ..  在c语言中两个无符号相减值为负数,该值却很大 有可能超出int unsign  表示的最大位数。

解决方法:CAST( 字段 as signed) 将无符号转成有符号类型

-- 查询错误订单
select
orderdetailid,
orderid,
updatetime,
amount,
takeamount,
refundamount,
CAST( amount AS signed) - CAST( takeamount AS signed) - CAST( refundamount AS signed)
from order_detail

相关文章:

  • 2021-12-02
  • 2021-04-21
  • 2021-10-20
  • 2021-11-22
  • 2021-08-28
  • 2021-08-05
  • 2022-12-23
  • 2022-02-10
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
相关资源
相似解决方案