select a,b,c,round(sum(case d when '1' then 1 else 0 end)::numeric/count(*)::numeric,2)from rhj_tmp group by a,b,c;