What can an aggregate function do in the ORDER BY clause?
Lets say I have a plant table: id fruit 1 banana 2 apple 3 orange I can do these SELECT * FROM plant ORDER BY id; SELECT * FROM plant ORDER BY fruit DESC; which does the obvious thing. But I was bitten by this, what does this do? SELECT * FROM plant ORDER BY SUM(id); SELECT * FROM plant ORDER BY COUNT(fruit); SELECT * FROM plant ORDER BY COUNT(*); SELECT * FROM plant ORDER BY SUM(1) DESC; All these return just the first row (which is with id = 1). What's happening underhood? What are the scenarios where aggregate function will come in handy in ORDER BY ? Your results are more clear if you