runtime
04 / 88

lesson 04 Filtering & sorting · beginner

Comparisons & ranges

Filter numbers and dates with comparisons and ranges.

the idea

Use >, >=, < and <= to compare values. BETWEEN includes both endpoints. Decide whether the task includes the boundary before choosing an operator.

tables in this lesson

The challenges use this data. Each column shows its type underneath; → marks a link to another table.

products4 columns · 6 rows
idinteger · keynametextcategorytextpricereal
1NotebookStationery12
2Desk lampHome45
3KeyboardTech80
4Pen setStationery8
5HeadphonesTech120

showing 5 of 6 rows

example

The idea in one query. Press Run to see what it returns; running examples never affects your progress.

example.sql
SELECT name, price
FROM products
WHERE price >= 45;

Watch for: Using > instead of >= drops the boundary row.

build it step by step

Each step changes one thing. Run them in order and watch the result change.

  1. Include the boundary. Look at the prices. A product at exactly 45 stays when the condition uses >=.

    step-1.sql
    SELECT name, price
    FROM products
    ORDER BY price;
  2. Run the reference. Use >, >=, < and <= to compare values. BETWEEN includes both endpoints. Decide whether the task includes the boundary before choosing an operator.

    step-2.sql
    SELECT name, price
    FROM products
    WHERE price >= 45;

challenge 1

Show name and price for products priced at least 45.

Return namepriceany row order

challenge-1.sql
 
To master this lesson, solve both challenges without hints and pass the concept check. 3 of 3 to go.