首先利用派生表或CTE得到合计金额
select ta.eid, ta.amount, tb.amount, tc.amount
from (select eid, amount= sum(amount) from ta group by eid) ta
join (select eid, amount= sum(amount) from tb group by eid) tb on ta.eid = tb.eid
join (select eid, amount= sum(amount) from tc group by eid) tc on ta.eid = tc.eid
如果
eid
可能不会出现在所有表中,您可以获得eid列表,然后
LEFT JOIN
至ta、tb、tc
select i.eid, ta.amount, tb.amount, tc.amount
from (select eid from ta union select eid from tb union select eid from tc) i
left join (select eid, amount= sum(amount) from ta group by eid) ta on i.eid = ta.eid
left join (select eid, amount= sum(amount) from tb group by eid) tb on i.eid = tb.eid
left join (select eid, amount= sum(amount) from tc group by eid) tc on i.eid = tc.eid