Drill 7 of 12 in SQL Basics
0

SQL Basics · ORDER BY · LIMIT

7. Three biggest orders

Concept: ORDER BY · LIMITshow

LIMIT n keeps only the first n rows of the result. It runs after ORDER BY, so 'sort, then cut' gives you a top-N list.

Example (different data):

SELECT title, views
FROM videos
ORDER BY views DESC
LIMIT 5;

Your task

The CEO wants to personally thank the customers behind the three largest orders. Refunded and pending orders don't count.

Return id, customer_id and amount of the 3 largest completed orders, largest first.

Solution unlocks after 3 more tries

Starting Postgres in your browser…

query.sql
Output

Write a query and press Run Query (Ctrl/⌘ + Enter).