I have two tables below.
Item Table
This Item Table contains ItemId and Total Quantity
ItemID TotalItems
1 10
2 10
3 10
4 10
OrderHistory
Table This Order history table contains ItemId and OrderId
orderId ItemID
11 1
12 1
13 2
14 2
15 3
I want to get result which contains ItemID and total Items Used for example for Item Id 1 , there are two order in orderhistory so I want result like below
Remaining Items( Formula : Total Items from ItemTable – count of Same ItemId from Orderhistory table)
Final output :
ItemId Remaining Items
1 8
2 8
3 9
4 10
so How to write SQL Query for that.
Something like this?