我有三张桌子。
A
ID NAME
--- ----
1 abc
2 asd
3 qwe
B
ID INCOME
--- ------
1 2
2 3
1 4
C
NAME TOTAL
---- ----
abc 8
asd 20
我想用SQL查询连接这三个表,以产生类似
的输出ID INCOME TOTAL
---------------
1 6 8
2 3 20
有人可以帮助我吗?
答案 0 :(得分:0)
你可以试试这个:
select
t1.id, sum(t2.income) income, sum(t3.total) total
from
table1 t1
join
table2 t2 on t1.id = t2.id
join
table3 t3 on t3.name = t1.name
group by
t1.id
order by
t1.id