[英]How to write a query to display SUM of the quantity if same product having same price in my inventory?
我的桌子看起來像
Product Price Qty
A 100 10
B 200 30
A 100 15
A 150 20
我的表中的產品 A 重復價格為 100 兩次。 如果產品的價格值相同,則應添加數量。 我的結果應該如下
Product Price Qty
A 100 25
A 150 20
B 200 30
只需group by product, price
與sum
聚合為:
select product, price, sum(qty)
from tab
group by product, price
order by product, price;
使用sum()
函數按產品和價格分組
select t.product, t.price,sum(t.qty) as Qty from your_table t
group by t.product,t.price
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.