Transform using group by