distinguishes between a group by or normal query, also gets the function to execute as a parameter