to implement different sql aggregate function