tableA :
tranactionid staffid amount
1001 19052 2000
1002 19043 3000
1004 19076 4000
tableB :
BudgetCode Budget
271098 20000
I want to sum Amount
in tableA
and subtract it from Budget
value 20000
20000 - 9000 = 11000
您必须使用:
SELECT (SELECT [Budget] FROM tableB) - (SELECT SUM([amount]) FROM tableA) AS [any_name]
This will work if TableB has just one row forever, but it's likely your requirements go beyond that:
SELECT tableB.Budget - (SELECT SUM(amount) FROM tableA)
FROM tableB.Budget;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.