Overview
Show each product's price with VAT: pick columns with SELECT, compute a new one, name it with AS and round money with ROUND.
- SELECT columns FROM table
- Calculations in SELECT
- AS names a column
- ROUND(x, 2) for money
Short Course
SELECT lists the columns you want, and a column can be a calculation; AS
gives it a name. Trap: money maths in floating point gives values like
23.987999999999996. Wrap it in ROUND(x, 2).
SELECT name,
price * 1.2 AS raw, -- 23.987999999999996
ROUND(price * 1.2, 2) AS with_vat -- 23.99
FROM products;
Task
Return each product's name and its price with 20% VAT (price * 1.2)
rounded to 2 decimals. In the database below, the Notebook costs 23.99 with
VAT.
Database
Sample data from the first test. The other tests use different rows, so write a query, not a list of answers.
| idINTEGER | nameTEXT | priceREAL |
|---|---|---|
| 1 | Notebook | 19.99 |
| 2 | Pen | 2.5 |
| 3 | Lamp | 35.0 |
Test Suites
Pending
Next
Output