mysql子查询结果相加减_MySQL子查询字段减法结果不正确

当我运行这个查询:

select

(IFNULL(ROUND(convertUnits('40892',SUM(o.qty),o.pricingUnit,'FT')),0)) as oItemQty,

(SELECT IFNULL(sum(i.qty),0) from inventory i where i.partID='40892' and i.type=16 and i.refDocNum=w.woID and i.refApp='WO') as iItemQty,

(IFNULL(ROUND(convertUnits('40892',SUM(o.qty),o.pricingUnit,'FT')),0) - (SELECT IFNULL(sum(i.qty),0) from inventory i where i.partID='40892' and i.type=16 and i.refDocNum=w.woID and i.refApp='WO')) as sum

from orderitem o left join wo w on o.orderitemID=w.orderitemID

where o.partID='40892' and

w.status not in (1,5) and

(SELECT cancelDate from orders where orders.orderID=o.orderID)='0000-00-00' and

o.createWO=1 and

(SELECT orderDate from orders where orders.orderID=o.orderID) >='2012-07-01'我得到“oItemQty”的13650和“iItemQty”的2730。我遇到的问题是字段“总和”应该是oItemQty - iItemQty(10920)。现在它正在返回13650(oItemQty)。

我在这里错过了什么?为什么当我运行子查询作为单独的字段是数字正确的,但是当我试图减去它不正常工作?

更新:原来这是一个铸造问题。一旦我将iItemQty作为未签名进行铸造,就会正确扣除它。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值