2017-07-31 23 views
-5
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 
+0

你有什麼試過? 你想要什麼樣的最終結果?你需要更具體的 – Eli

+1

向我們展示數據庫模式,樣本數據和預期輸出。 \t請閱讀[**如何提問**](http://stackoverflow.com/help/how-to-ask) \t \t這裏是一個偉大的地方[** START **] (http://spaghettidba.com/2015/04/24/how-to-post-at-sql-question-on-a-public-forum/)來了解如何提高您的問題質量並獲得更好的答案。 \t [**如何創建最小,完整的,並且可驗證示例**](http://stackoverflow.com/help/mcve) \t嘗試在http://rextester.com –

回答

0

試試這個:

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

返回到你的2列...

請添加更多的信息,像例子,如果這不是你想要的。

+0

table1中創建一個示例(itemid,openingstock),table2(itemid.entrydate,stockin,stockout) – vijay

+0

@vijay我用你的新信息編輯我的答案,現在好嗎? – M84