N003-M1 Tier 1 · Foundations · medium ecommerce · Brightlane

Return the name, original price, and discounted price for each qualifying product

Part of WHERE Clause and Comparison Operators in SQL

The problem

Brightlane's promotions team is configuring a flash sale that applies a 10% discount to all products priced under $50.

Write a query to return the name, original price, and discounted price for each qualifying product.

Assumptions:

  • The products table contains every item in Brightlane's catalog.
  • The price column records each product's regular selling price in dollars.
  • The discounted price is the original price multiplied by 0.9 (a 10% reduction).

Output:

  • One row per qualifying product, with columns name, price, and discounted_price.
Schema · ecommerce 5 tables
categories
id integer
name text
parent_id? integer
products
id integer
name text
category_id integer
price numeric
stock_qty integer
attributes? jsonb
order_items
id integer
order_id integer
product_id integer
quantity integer
unit_price numeric
customers
id integer
name text
email text
city? text
country text
created_at timestamptz
is_active boolean
orders
id integer
customer_id integer
ordered_at timestamptz
status text
total_amount numeric

Run previews · Check grades

Write a query, then run it to see results here.

Worked solution Try it yourself first
Solution query
SELECT
  name,
  price,
  price * 0.9 AS discounted_price
FROM
  products
WHERE
  price < 50

The shape

Two independent jobs in one query — WHERE decides which products qualify for the flash sale, and SELECT builds the discounted price for the ones that do.

Clause by clause

  • SELECT name, price, price * 0.9 AS discounted_price returns three columns per surviving row. The first two come straight from the table; the third is computed on the fly by multiplying price by 0.9, which is the same as taking 10% off. The AS alias labels the new column so the result reads as a domain quantity instead of ?column?.
  • FROM products is the source — every item in Brightlane's catalog.
  • WHERE price < 50 filters down to the products under $50. Strict < excludes the boundary, so a product priced at exactly $50 would not qualify. The filter runs against the raw price column, not the discounted one.

Why the filter uses price, not discounted_price

The alias discounted_price doesn't exist yet at the time WHERE runs. PostgreSQL evaluates FROM first to establish the population of rows, then WHERE to filter, and only later does SELECT produce the output columns and assign their aliases. By the time discounted_price is a name, the filtering is over. Trying to write WHERE discounted_price < 45 would raise an error: the column doesn't exist at that stage of the query. The filter has to be written against the source column the table actually has.

You practiced filtering rows AND computing a derived column in the same query. WHERE decides which rows go through, SELECT decides what each row looks like — they're independent layers.

How you actually get good at SQL

Reading explains SQL. Writing it, over and over with instant feedback, is what makes you fluent.

That's the whole SQLMaxx loop: 600+ real problems, instant AI feedback, mastery you can actually see, and spaced review that won't let you forget.

A stack of SQL practice problem cards, the top card showing an employees table.
615 problems · 66 concepts

Real problems. Not toy examples.

615 hand-built problems spanning all 66 concepts, from basic SELECTs to window functions, built on real schemas and real business questions, the kind you'll actually get asked on the job. Enough reps to make SQL automatic.

A retro computer showing a SQL query marked correct with a green checkmark.
Instant AI feedback

Write a query. Know if it's right in one second.

No copying an answer and hoping it clicked. The AI grader checks your real query against real data, catches exactly what's wrong, and explains the fix in plain English, like a senior analyst reading over your shoulder on every problem.

A circular mastery progress dial filling from blue to green, the SQLMaxx diamond at its center.
Mastery tracking

Stop guessing whether you actually know it.

SQLMaxx tracks every concept and shows you what you've mastered and what's still shaky. Your skills fill in one concept at a time, so 'I think I get joins' becomes something you can prove.

A SQL query editor circled by a blue return arrow with a clock, scheduled to come back for review.
Spaced review

Learn it once. Keep it for good.

Most of what you learn this week fades by next week. So when a concept comes due for review, SQLMaxx hands you a fresh problem to solve from a blank editor, not a flashcard to re-read. A research-backed spaced-repetition algorithm (FSRS) times each return for right before you'd forget, so your SQL is still there months later, when the interview or the job actually needs it.

Practice, feedback, mastery, review. That's the loop that turns reading into real skill.

Start free

No account, no credit card. Start solving in under a minute.