I have an application(C#) that manages a stock level for every storage unit. But now i want a complete overview of the stock level of every product from every stock unit together.
For example i have 50
apples (ProductID 1) in unit one and 25
in unit two and I use this query:
select StockLevel
from Supply
where ProductID = '1'
And put the result in a textbox it will always gives me the first stocklevel of 50 apples and not 75 .
Is there a way i can combine these results in an easy way?
If you want to combine , you want an aggregate function , sum
in your case:
select sum(StockLevel)
from Supply
where ProductID = '1'
and get the apples being summed up: 75
which is 50 + 25
你可以这样尝试
SELECT (select sum(stock) from tablename where ProductID = 1) + (select sum(stock) from tablename where ProductID =1) as result
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.