简体   繁体   English

如何使用内联接求和

[英]HOW TO USE SUM WITH INNER JOIN

Ok I have here 好,我在这里

tbl_one
    id
    amount
tbl_two
    id
    amount

is it posible to get the sum of amount in tbl_one and tbl_two using inner join ?? 是否可以使用内部连接在tbl_onetbl_two获得sum can someone know how to do it ? 有人知道怎么做吗? THANKS IN ADVANCE . 提前致谢 。

Assuming you can join on id: 假设您可以加入id:

SELECT a.id, sum(a.amount+b.amount) as total
      from tbl_one as a JOIN tbl_two as b
      ON a.id = b.id
GROUP BY a.id

That is also assuming that you need to group, otherwise you can drop the sum and the GROUP BY. 这也假设您需要分组,否则可以删除总和和GROUP BY。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM