Each aisle gets its own discount
- O(log n) · Easy
- Free
- SQL
- conditionals
- operations
- decimals
Problem
New stock is on its way and the store has to make room. This week, everything in Accessories is 20% off and everything in Audio is 10% off. Nothing else changes.
To print the labels, show each product's name, today's price, and this week's price, in that order, with the last one rounded to 2 decimals. The Monitor's label gets printed too: it has the same price twice, and no label goes out with a blank price.
What it has to return
These rows, in any order
| name | price | this_week |
|---|---|---|
| Keyboard | 45.5 | 36.4 |
| Mouse | 19.9 | 15.92 |
| Monitor | 189 | 189 |
| Cable | 5.25 | 4.2 |
| Laptop | 899 | 899 |
| Tablet | 320 | 320 |
| Headphones | 59.9 | 53.91 |
| Speaker | 74 | 66.6 |
This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.
You start with this
SQL
SELECT name, price,
ROUND(price * 0.8, 2) AS this_week
FROM products;It opens in your browser, with the editor and the tests. It is free and you do not need an account to start.