2
我還沒有在現有問題中找到類似的表結構,所以我希望有人能夠提供幫助。Mysql查詢計算SKU銷售的產品總數
我想總結一下產品的訂單總量及其與下面兩個表的結構收入:
orders
trans_id | account_id | type
1 | 1 | credit
2 | 1 | credit
3 | 1 | void
4 | 2 | credit
orderlineitems
order_trans_id | sku | quantity | unitPrice
1 | sku1 | 1 | 5
1 | sku2 | 3 | 3
2 | sku1 | 5 | 5
4 | sku1 | 2 | 22.99
所以我想總結一下所有的數量對於一個給定ACCOUNT_ID其中類型是信用。所以我應該有:
Account ID = 1
sku | quantity
sku1 | 6
sku2 | 3
Account ID = 2
sku | quantity
sku1 | 2