如何使用SQL查询在此示例中获取打开和关闭库存

时间:2017-07-31 15:40:15

标签: sql-server stored-procedures

itemid  entrydate       opeingstock stockin  stockout       closingstock
DB07    02-10-14 23:05   94000        0        900            93100
DB07    03-10-14 23:05   93100      1000        0             94100
DB07    03-10-14 23:06   94100        0        500            93600
DB07   14-10-14 23:52    97600        0       1500            96100 

1 个答案:

答案 0 :(得分:0)

试试这个:

select 
      TABLE1.openingstock, 
      (TABLE1.openingstock + TABLE2.stockin - TABLE2. stockout) 'closingstock'
from 
     TABLE1 INNER JOIN TABLE2
     ON TABLE1.itemid = TABLE2.itemid

返回2列......

如果这不是您想要的,请添加更多信息,例如示例。