array query distinct groupby count sum