1

I have two tables, as below:

Inputs and result

I'm hoping to create a view, where the result is as per the result above. That is, the Act column is the total of all matching records between tbl1 and tbl2.

Additional explaination, graphically:

enter image description here

1
  • 1
    You're looking for JOIN and aggregate functions (specifically SUM). What have you tried so far? Please do share your attempts so we can show you where you might have gone wrong, or not quite got it right. Commented Feb 16, 2019 at 19:04

1 Answer 1

2

I'd left join tbl1 with an aggregate query on tbl2:

SELECT    t1.id, t1.req, COALESCE(t2.act, 0) AS act
FROM      tbl1 AS t1
LEFT JOIN (SELECT   id, SUM(act)
           FROM     tbl2
           GROUP BY id) t2 ON t1.id = t2.id
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.