Business context
The sales department wants to examine as a priority orders whose amount exceeds €50. The descending ranking allows it to start with the most important files. This query separates two responsibilities: WHERE defines the scope and ORDER BY organizes only the retained rows.
The sales department wants to examine as a priority orders whose amount exceeds €50. The descending ranking allows it to start with the most important files. This query separates two responsibilities: WHERE defines the scope and ORDER BY organizes only the retained rows.
Skills practised
- Translate a business threshold into a predicate WHERE
- Choosing between strict superior and superior or equal
- Produce a repeatable order with ORDER BY
Available tables
Table commandes
| Column | Type | Role |
|---|---|---|
id_commande | INTEGER | primary key |
id_client | INTEGER | customer concerned |
date_commande | DATE | date |
montant | DECIMAL | amount in € |
| montant | id_client | id_commande | date_commande |
|---|---|---|---|
| 134 | 1 | 101 | 2026-07-03 |
| 89 | 2 | 102 | 2026-07-04 |
| 45 | 1 | 103 | 2026-07-06 |
Your task
Show id_commande and amount for orders over €50. Sort the result by descending amount.
For "Filter and sort orders", the success contract requires 2 rows, with columns id_commande, amounting to the requested level of detail. Control mark on the first line: id_commande=101 · amount=134.
Build your reasoning
- Identify the relevant numeric column: amount.
- The word exceed imposes the strict > operator, so an order of €50 would be excluded.
- Request a sort on this same column with DESC.
- Verify that 134 precedes 89 and that 45 does not appear.
SELECT id_commande, montant
FROM commandes
WHERE -- your filter
ORDER BY -- your sorting;Browser-based SQL environment
Interactive SQL editor
Run a read-only query on this exercise's fictional data. Nothing is sent to SQL.tn.
Expected result
| id_commande | montant |
|---|---|
| 101 | 134 |
| 102 | 89 |
Explained answer
Extra challenge
Extend the query
Keep only the two highest orders of those over $50 and explain why LIMIT should come after ORDER BY.