added group by with average and sum operation