Add a missing "GROUP BY" for the sorting function.