I have these two queries:
-- 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.
I need to compare the sums of those two columns from different tables to see if a sales order is complete or not.
If 1 is returned, meaning the no. of items claimed is equal to no. of items ordered, it means the sales order is completed. Otherwise, the sales order remains unclaimed/partially claimed.
This is by far the best solution I can think of, but I wish to write it in a single query that will only return one value, if that's possible. But if you have better suggestions, I'm all ears.