• This is probably over kill, but if you might not have the same id in both tables this will give you all:

    select a.id, a.e - a.f as Diff

    FROM (select id, sum(a)/count(id) as e, 0 as f from table1 group by id

    union all

    select id, 0 as e, sum(b)/count(id) as f from table2 group by id) as a

    group by a.id