我简单的表名为ass_material与此列:计算在MySQL运行平衡,观点
mat_id mat_name supplier request stock_received date
1 alloy test 30 0 feb13
2 alloy test 30 10 feb14
3 alloy test 30 20 feb14
我怎样才能产生,或计算出它作为: 它也将产生一个“完整”的状态时stock_balance和要求火柴。
mat_id mat_name supplier request stock_received Stock_balance date status
1 alloy test 30 0 0 feb13
2 alloy test 30 10 10 feb14
3 alloy test 30 20 30 feb14 complete
这里是我的引用代码从我的另一种观点: 我如何可以调整到我所期望的输出这上面?
SELECT m.`mat_id`, m.`mat_name`, m.`request`, m.`stock_receieved`,
(select sum(stock_received) - sum(stock_received)
from material m2
where m2.mat_name = m.mat_name and
m2.mat_id <= m.mat_id
) as Stock_balance,
m.`date`,
s.`sup_name`
FROM `material` m
LEFT JOIN `supplier` s on s.sup_id = m.supplier_id
ORDER BY m.`mat_id` ASC;
你是如何解决的库存余额? –
当收到股票时,它会将先前的stock_received累计到stock_balance。 – user3117337