Add SQL Function and Group BY Clause