"sql subtract" Code Answer's
You're definitely familiar with the best coding language SQL that developers use to develop their projects and they get all their queries like "sql subtract" answered properly. Developers are finding an appropriate answer about sql subtract related to the SQL coding language. By visiting this online portal developers get answers concerning SQL codes question like sql subtract. Enter your desired code related query in the search bar and get every piece of information about SQL code related question on sql subtract.
sql subtract
I think this is what you're looking for. NEW_BAL is the sum of QTYs subtracted from the balance:
SELECT master_table.ORDERNO,
master_table.ITEM,
SUM(master_table.QTY),
stock_bal.BAL_QTY,
(stock_bal.BAL_QTY - SUM(master_table.QTY)) AS NEW_BAL
FROM master_table INNER JOIN
stock_bal ON master_bal.ITEM = stock_bal.ITEM
GROUP BY master_table.ORDERNO,
master_table.ITEM
If you want to update the item balance with the new balance, use the following:
UPDATE stock_bal
SET BAL_QTY = BAL_QTY - (SELECT SUM(QTY)
FROM master_table
GROUP BY master_table.ORDERNO,
master_table.ITEM)
This assumes you posted the subtraction backward; it subtracts the quantities in the order from the balance, which makes the most sense without knowing more about your tables. Just swap those two to change it if I was wrong:
(SUM(master_table.QTY) - stock_bal.BAL_QTY) AS NEW_BAL
All those coders who are working on the SQL based application and are stuck on sql subtract can get a collection of related answers to their query. Programmers need to enter their query on sql subtract related to SQL code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about sql subtract for the programmers working on SQL code while coding their module. Coders are also allowed to rectify already present answers of sql subtract while working on the SQL language code. Developers can add up suggestions if they deem fit any other answer relating to "sql subtract". Visit this developer's friendly online web community, CodeProZone, and get your queries like sql subtract resolved professionally and stay updated to the latest SQL updates.