Problem Statement
After aggregating, which is the simplest way to sort by the computed total?
Explanation
Most engines allow ORDER BY on a SELECT alias. It keeps the query clean and avoids repetition.
If your engine forbids it, repeat the expression or use the ordinal position carefully.
Code Solution
SolutionRead Only
SELECT customer_id, SUM(total) AS spend FROM sales GROUP BY customer_id ORDER BY spend DESC;
Practice Sets
This question appears in the following practice sets:
