当我运行这个查询:
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作为未签名进行铸造,就会正确扣除它。