这是我的SQL查询
SELECT product.productNum, product.description, prod_location.quantityOnHand
FROM product
INNER JOIN prod_location ON prod_location.productNum = product.productNum
这是输出。
productNum | description | quantityOnHand
660 | Reflex Paper| 100
660 | Reflex Paper| 95
660 | Reflex Paper| 64
661 | Window Clean| 200
661 | Window Clean| 67
661 | Window Clean| 38
662 | Acid | 300
662 | Acid | 100
662 | Acid | 100
663 | Pens | 400
663 | Pens | 200
663 | Pens | 153
664 | Door Mats | 200
我如何得到它,以便将每个productNum的quantmentOnHand相加在一起,所以它不是说是Reflex Paper的3行
productNum | description | quantityOnHand
660 | Reflex Paper| 259
661 | Window Clean| 305
662 | Acid | 500
663 | Pens | 753
664 | Door Mats | 200
任何帮助是极大的赞赏。
最佳答案
像这样
SELECT product.productNum, product.description, SUM(prod_location.quantityOnHand) as quantityOnHand
FROM product
INNER JOIN prod_location ON prod_location.productNum = product.productNum
GROUP BY product.productNum