Brightlane's promotions team is running a member-only sale that applies a 20% discount to all products priced between $100 and $500, inclusive.
Write a query to return each qualifying product's name, its regular price, and its discounted member price (the regular price scaled by 0.8).
Assumptions:
- The
productstable contains every product in Brightlane's catalogue. - A product priced exactly at
$100or exactly at$500qualifies for the sale.
Output:
- One row per qualifying product, with columns
name,price, andmember_price.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
price,
price * 0.8 AS member_price
FROM
products
WHERE
price BETWEEN 100 AND 500 The shape
BETWEEN 100 AND 500 selects the eligible products, and a derived price * 0.8 column in the SELECT list produces the member price alongside the regular price in a single row per product.
Clause by clause
SELECT name, price, price * 0.8 AS member_pricereturns three columns. The first two come straight off the row — the product label and its regular price. The third is computed: each row'spricemultiplied by0.8, labelledmember_price. SQL evaluates the multiplication once per row, against that row'sprice, soCoffee Tableat249produces199.2andPatio Setat499produces399.2.FROM productsreads the catalogue.WHERE price BETWEEN 100 AND 500keeps only the rows whosepricefalls in the inclusive range. A product priced at exactly100qualifies —Gift Card $100is in the result for that reason — and the upper bound at500is included the same way.
Why this and not filtering on member_price
The filter has to be expressed in terms of price, not member_price. SQL evaluates WHERE before SELECT — at the time WHERE runs, the member_price alias doesn't exist yet because the SELECT list hasn't been computed. Writing WHERE member_price BETWEEN 100 AND 500 would raise an error.
It's also the wrong question. The prompt says the sale applies to products priced between $100 and $500 — the regular price is the qualifying number. The 20% discount changes what the customer pays, not what makes the product eligible. So the filter goes on the stored value, the derived column shows the discounted price, and the row carries both for the team to see at once.
You practiced combining a BETWEEN filter with a derived column in the SELECT list. The recurring shape: filtering on a stored value while presenting both the stored value and a value computed from it side by side.