Can you sort groups by an aggregate that isn't in SELECT?
Find the two customers with the highest combined value of paid orders. Return only customer_id, without displaying the totals. Here's the query: SELECT customer_id FROM iv_orders WHERE status = 'paid' AND customer_id IS NOT NULL GROUP BY customer_id ORDER BY SUM(total) DESC, customer_id LIMIT 2. Can you use SUM(total) in ORDER BY even though it doesn't appear in SELECT? Explain why, and describe the logical order in which the query is processed.
ExplainQuery execution orderMiddleAnalystData EngineerBackend