Skip to main content
SQL Code Reorder Hard +35 XP

Complex Query

Arrange this analytics query.

Click lines in the correct order

Available lines7 left

Your order

Click lines above to build your solution.

Show answer and explanation

Answer: SELECT c.name, COUNT(o.id) AS total_orders, SUM(o.amount) AS revenue FROM customers c LEFT JOIN orders o ON c.id = o.customer_id GROUP BY c.name HAVING COUNT(o.id) >= 5 ORDER BY revenue DESC LIMIT 10

SQL order: SELECT, FROM, JOIN, GROUP BY, HAVING, ORDER BY, LIMIT.

Hint: Remember the SQL clause execution order.

What this challenge tests

Code Reorder in SQL: complex-queries, clause-order.

Related challenges