你好,我有两张table:
表:1 11_counted_stock
id_counted_stock part_number Number of Tag quantity
1 abcde 2 1000
2 aaaaa 4 222
3 eeeee 6 442
表:2 11库存实际成本
id_stock material batch A.stock
1 abcde 12334 500
2 aaaaa 23543 233
3 xxxxx 234234 299
结果查询我正在查找
Material Stock Counted_Stock Difference
abcde 500 1000 -500
aaaaa 233 222 11
eeeee 0 442 -442
xxxxx 299 0 299
谢谢!
这是我最好的尝试,但我只能总结:(
SELECT mat, qty, SUM(qty) as TotalQty
FROM (
SELECT 11_counted_stock.part_number AS mat, (11_counted_stock.quantity) AS qty
FROM 11_counted_stock
GROUP BY 11_counted_stock.part_number
UNION
SELECT 11_stock_actual_whs_costed.material, SUM(11_stock_actual_whs_costed.available_stock) AS quantity
FROM 11_stock_actual_whs_costed
GROUP BY 11_stock_actual_whs_costed.material
) as t
GROUP BY mat
;
1条答案
按热度按时间oxiaedzo1#