我有两个疑问:比较来自不同表格的两列的SUM()?
-- Getting the total no. of items CLAIMED for a sales order
SELECT SUM(qty_claimed) As 'total_items_claimed'
FROM so_claim_item
WHERE sales_order_id = 1;
-- Getting the total no. of items originally ORDERED for a sales order
SELECT SUM(quantity) As 'total_items_ordered'
FROM sales_order_item
WHERE sales_order_id = 1;
-- If the sums of the two columns are equal, return 1 or true.
-- Else, return 0 or false.
我需要比较不同表这两列的总和,看是否销售订单是否完成。
如果返回1,意味着没有。的项目声称等于没有。订购的物品,这意味着销售订单已完成。 否则,销售订单将保持无人认领/部分声明。
这是迄今为止我能想到的最好的解决方案,但我希望将它写入一个查询,只会返回一个值,如果可能的话。但是,如果你有更好的建议,我全都耳熟能详。