1
SELECT table.productid, product.weight
FROM table1
INNER JOIN product
ON table1.productid=product.productid
where table1.box = '55555';

Basically it's an inner join that looks at a list of products in a box, and then the weights of those products.

So i'll have 2 Columns in my results, the products, and then the weights of each product.

Is there an easy way to get the SUM of the weights that are listed in this query?

Thanks

4 Answers 4

1
SELECT table.productid, SUM(product.weight) weight
FROM table1
      INNER JOIN product
      ON table1.productid=product.productid
where table1.box = '55555'
Group By table.productid
Sign up to request clarification or add additional context in comments.

Comments

0

This will give you the total weight for each distinct productid.

SELECT table1.productid, SUM(product.weight) AS [Weight]
FROM table1 INNER JOIN product ON table1.productid = product.productid
WHERE table1.box = '55555'
GROUP BY table1.productid

Comments

0

Not clear about the issue here, you just want the total weight or the grouping?

SELECT Sum(product.weight)
FROM table1
INNER JOIN product
ON table1.productid=product.productid
where table1.box = '55555';

will give the total.

Comments

0

I read it as you wanted a sum of the weights for that box as well as the rows for each product. I could be wrong but if not, here goes.

SELECT table1.productid, product.weight, SUM(weight) Over(PARTITION BY table1.box) AS SumWeights
FROM table1
INNER JOIN product
ON table1.productid=product.productid
WHERE table1.box = '55555'; 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.