IM面临SQL有点问题加入SQL鲜明加入
我有2个表
*1st table* *2nd table*
Reference Name Reference Amount
123 Test1 123 52
145 Test2 232 22
123 Test3 123 33
555 Test4 145 44
123 Test5 656 55
我需要这样的东西
select distinct(a.reference), sum(b.amount) from 1st a left join 2nd b ON a.Reference = b.Reference group by a.reference
这看起来很简单,对我来说它做什么 - 它给我多次SUM参考是123,所以它会给我(52 + 33)* 3
我应该使用什么来获得每个引用的唯一SUM?
Thx!
编辑:
最终的结果应该看起来像
123 85
145 44
请编辑您的问题,并提供您正在寻找的结果。你不会在任何地方解释你想要什么。 –