No-account exercise · WHERE · ORDER BY

Filter then sort a threshold

Keep the threshold inclusive and make the outcome controllable.

Business context

An advisor prepares a selection of references above a budget threshold given by his client. Your answer must be verifiable by another person: respect the level of detail requested, use explicit aliases and control the number of records returned before drawing a business conclusion. The data is fictitious and is used for learning purposes only.

Skills practised

  • WHERE
  • Interpreting the result
  • Checking the level of detail

Available tables

Table produits

produits schema
ColumnTypeRole
id_produitINTEGERunique identifier
produitVARCHARfictitious name
categorieVARCHARfamily
marqueVARCHARfictitious brand
prixDECIMALselling price in TND
coutDECIMALunit cost in TND
stockINTEGERunits available
Sample data from produits
coutprixstockmarqueproduitcategorieid_produit
558912AtlasPro KeyboardIT1
28450AtlasAir MouseIT2
41280CarthageA5 NotebookOffice3
20348MedinaFocus LampOffice4
102518AtlasUSB-C CableAccessories5
355814KairouanUrban BagTravel6
761206MedinaVision WebcamIT7
427542CarthageMonitor StandOffice8

Your task

Show product and price for products costing at least 50 TND, from most expensive to least expensive.

Build your reasoning

  1. Rephrase the mission and its level of detail: Display product and price for products costing at least 50 TND, from most expensive to least expensive.
  2. Locate the necessary columns in products before applying WHERE · ORDER BY.
  3. First build the structure that must return product, price, then add the filters or calculations.
  4. Check the 4 expected lines and explain a value with the source data.
Query to complete
SELECT produit, prix
FROM produits
WHERE -- inclusive threshold
ORDER BY -- 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
produitprix
Vision Webcam120
Pro Keyboard89
Monitor Stand75
Urban Bag58

Explained answer

Extra challenge

Extend the query

Add a second alphabetical criterion to stabilize the ranking in the event of a price tie. Describe in one sentence the control you would add before sharing this result in a report.