unsign 字段相减出现负数解决方法
在项目中做数据统计的时候需要用到几个字段相减得到想要的值,但是因为字段都是无符号,相减出现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 
 
                    
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号