GROUP BY comes before ORDER BY

This generated an error in queries