0

I have 2 tables, table A:

CategoryId | Qty

1 | 10
2 | 15

Table B:

SaleId | CategoryId | QtyReserved

1 | 1 | 2
2 | 1 | 1
3 | 2 | 5

I want to display result like this (joining both tables):

CategoryId | Qty | QtyReserved

1 | 10 | 3 ---> sum records (column QtyReserved) from table B
2 | 15 | 5

How can I possibly achieve this? Thank you.

1
  • hint... SUM ... GROUP BY... Commented Nov 2, 2018 at 11:03

1 Answer 1

2

use SUM and GROYP BY

SELECT  C.CategoryId,C.Qty,SUM(S.QtyReserved) AS QtyReserved
FROM    tableA AS C
INNER JOIN tableB AS S ON C.CategoryId = S.CategoryId
GROUP BY C.CategoryId,C.Qty
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.