目前我有这样的表:
表客户
ID Name
01 Angel
02 Charlie
表输入1
Name Value
Charlie 5
Angel 7
Charlie 10
Angel 3
表输入2
Name Value
Charlie 10
Angel 5
Charlie 15
Angel 25
如何获得这样的结果
Name Input1 Input2
Angel 10 30
Charlie 15 25
答案 0 :(得分:2)
试试这个:
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
<强>样本强>