select group1, format(sum(c1_mult), 'N') c1, format(max(product_c2), 'N') as c2 from (select group1, c1*exp(sum(log(c2)) over (partition by group1))/c2 c1_mult, exp(sum(log(c2)) over (partition by group1)) product_c2 from (values ('1', 1, 2), ('1', 2, 1.4), ('1', 3, 5.2), ('2', 1, 0.6), ('2', 4, 0.5), ('2', 3, 0.9)) as tab1(group1, c1, c2) ) as t group by group1 order by group1;