![](/img/trans.png)
[英]How to perform an action on one result at a time in a sql query return that should return multiple results?
[英]Combine the results of a sql query together in one result
我有一個應用程序(C#),它管理每個存儲單元的庫存水平。 但是,現在我希望對每個庫存單位的每種產品的庫存水平有一個完整的了解。
例如,我在第一單元中有50
蘋果(產品ID 1),在第二單元中有25
50
蘋果,我使用以下查詢:
select StockLevel
from Supply
where ProductID = '1'
並將結果放在一個文本框中,它總是給我第一個庫存的蘋果是50個蘋果,而不是75個 。
有沒有一種方法可以輕松組合這些結果?
如果要合並 ,則需要聚合函數 , sum
為:
select sum(StockLevel)
from Supply
where ProductID = '1'
得到蘋果的總和: 75
等於50 + 25
你可以這樣嘗試
SELECT (select sum(stock) from tablename where ProductID = 1) + (select sum(stock) from tablename where ProductID =1) as result
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.