If ASC or DESC is included in an order by that uses a function, then the query is not composed properly.
-SELECT ProductCode FROM Product2 GROUP BY ProductCode HAVING COUNT(Id) > 1 ORDER BY COUNT(Id)DESC
+SELECT ProductCode FROM Product2 GROUP BY ProductCode HAVING COUNT(Id) > 1 ORDER BY COUNT(Id) DESC
Description
If ASC or DESC is included in an order by that uses a function, then the query is not composed properly.