select sum(amount), footype from foo where databaseid in (1,2,3) group by footype