这是我的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相加在一起,所以它只是说反光纸而不是3行
productNum | description | quantityOnHand
660 | Reflex Paper| 259
661 | Window Clean| 305
662 | Acid | 500
663 | Pens | 753
664 | Door Mats | 200
非常感谢您的帮助。
答案 0 :(得分:0)
类似这样的东西
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
答案 1 :(得分:0)
如果product
表和prod_locatoin
表之间的关系是一对多的。并且prduct.productNum
是唯一的
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