有3个表,
表stork
Material, Quantity, Date
K001 , 12, 2019-10-18
K002 , 23, 2019-10-18
K003 , 19, 2019-10-18
K004 , 8, 2019-10-18
K005 , 3, 2019-10-18
表requirement
Material,Quantity,Date
K001 , 24, 2019-10-19
K002 , 15, 2019-10-19
K004 , 3, 2019-10-19
表order
Material,Quantity,Date
K001 , 50 , 2019-10-18
K003 , 20 , 2019-10-18
其中表requirement中没有K003和K005,
其中表order中没有K002,K004和K005
只有Stock中的Material字段是全的。
要实现 2019-10-19日的stork,计算工式:
stock(N天)=stock(N-1天)+order(N-1天)- requirement(N天)
把计算结果保存到Stock表中,SQL语句怎么写?