也许主题不准确
但我有一个问题,如何将数据插入表中并计算它们。
我有一张桌子
no date product_code first_stok in out final_stock
1 2018/01/18 A001 50 0 0 50
2 2018/01/18 A001 0 0 35 15 <==== i want to achieve this
当我插入新数据(数据编号2)并填写列&#34;输出&#34; 35岁的&#34; final_stock&#34;列将有15.我怎样才能实现
这是我的查询
mysql_query("insert into flow_stock (date, product_code, first_stok, in, out, final_stock )
values('$date', '$code','','','$out','')");
mysql_query("update flow_stock set final_stok = final_stok-'$out'
where product_code ='$code'");
需要你的帮助
答案 0 :(得分:0)
你可以这样做:
mysql_query("insert into flow_stock (date, product_code, first_stok, in, out, final_stock )
values('$date', '$code','','','$out',(select final_stock from flow_stock order by no desc limit 1) - ".$out.")");