No-account exercise · WHERE · ORDER BY

Filter and sort orders

Find orders over 50 TND, from highest to lowest.

Business context

The sales department wants to examine as a priority orders whose amount exceeds 50 TND. 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 TND
Sample data from commandes
montantid_clientid_commandedate_commande
13411012026-07-03
8921022026-07-04
4511032026-07-06

Your task

Display id_commande and Amount for orders exceeding 50 TND. Sort the result by descending amount.

Build your reasoning

  1. Identify the relevant numeric column: amount.
  2. The word exceed imposes the strict > operator, so a command of 50 TND 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 that exceed 50 TND and explain why LIMIT should come after ORDER BY.