简体   繁体   中英

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 ?? can someone know how to do it ? THANKS IN ADVANCE .

Assuming you can join on 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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