for exmaple
select sum(a) over(partition by aa) as x, sum(b) over(partition by bb) as y, (x- y) / y as c -- look here from table