1

I need to make a query that sums a column based on a value from another table.

So I have two tables

PROJECT

PROJECT_NO PROJECT_NAME
W14026     SMSMILLHOUSE
W14026     SMSSUGARWHOUSE
W14026     SMSBOILERHOUSE
W-IGG      IGGMILLHOUSE
W-IGG      IGGBOILERHOUSE

DTL_ERC_UPD

PROJECT_NAME   QUANTITY
SMSMILLHOUSE   5
SMSMILLHOUSE   2
SMSBOILERHOUSE 3
IGGMILLHOUSE   4
IGGMILLHOUSE   5

So i want to sum all the W14026 project that is in DTL_ERC_UPD. that should give the output of 10. I dont know how to approach that. I know simple join just doesnt work. Please help me,

1
  • 1
    What do you mean by simple join didn't work ? Commented Feb 10, 2015 at 7:41

2 Answers 2

3
select project_no, sum(d.quantity) 
from project p join dtl_erc_upd d
on p.project_name=d.project_name
group by project_no
Sign up to request clarification or add additional context in comments.

Comments

0

This should solve all your problems:

SELECT SUM(dtl_erc_upd.quantity) AS project_count 
FROM dtl_erc_upd 
INNER JOIN project 
ON project.project_name = dtl_erc_upd.project_name 

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.