select sum(sum_amount), footype from ( select sum(amount) as sum_amount, footype from db1.foo group by footype UNION ALL select sum(amount) as sum_amount, footype from db2.foo group by footype UNION ALL ... UNION ALL select sum(amount) as sum_amount, footype from dbN.foo group by footype ) group by footype