Firebird SQL join tables

Currently I have tables like these:

Table Customer

ID Name 01 Angel 02 Charlie 

Table Input1

Name Value Charlie 5 Angel 7 Charlie 10 Angel 3 

Table Input2

Name Value Charlie 10 Angel 5 Charlie 15 Angel 25 

How to get result like this

Name Input1 Input2 Angel 10 30 Charlie 15 25 
6

1 Answer

Try this:

SELECT c.Name, i1."Value" value1, i2."Value" value2 FROM Customer c LEFT JOIN (SELECT Name, SUM("Value") "Value" from input1 group by Name) i1 ON c.Name = i1.Name LEFT JOIN (SELECT Name, SUM("Value") "Value" from input2 group by Name) i2 ON c.Name = i2.Name 

DEMO

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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

You Might Also Like