No-account exercise · WHERE · ORDER BY

Filter and sort orders

Find orders over €50, from highest to lowest.

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.

Why this skill matters

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

commandes schema
ColumnTypeRole
id_commandeINTEGERprimary key
id_clientINTEGERcustomer concerned
date_commandeDATEdate
montantDECIMALamount in €
Sample data from commandes
montantid_clientid_commandedate_commande
13411012026-07-03
8921022026-07-04
4511032026-07-06

Your task

Show id_commande and amount for orders over €50. Sort the result by descending amount.

Result to produce

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

  1. Identify the relevant numeric column: amount.
  2. The word exceed imposes the strict > operator, so an order of €50 would be excluded.
  3. Request a sort on this same column with DESC.
  4. Verify that 134 precedes 89 and that 45 does not appear.
Query to complete
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.

Local and private
Shortcut: Ctrl/⌘ + Enter
The SQL environment will be prepared when you first run the query.

Expected result

Expected result
id_commandemontant
101134
10289

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.