AI Hints
Homeโ€บSQL Tutorialโ€บCalculations and Labels
SQL ยท Lesson 23 of 126

Practice: Prices and Labels

Put it together.

โฑ 2 min readโ–ถ Video at 32:08๐ŸŽ“ Free
Watch this lesson in the SQL courseWatch on YouTube โ†—Full SQL course

Time to practise. Prices of technology books are going up by ten percent. Helen wants to see each technology book, its old price, and its new price, rounded to two decimal places.

Practice: Prices and Labels
From the video: Practice: Prices and Labels
  • Tech prices up 10%
  • Old and new price
  • Rounded to two decimals

A price rise

Pause the video, and write the query. You'll need a calculation, round, an alias, and a where test. Here's one solution. Price times one point one, rounded to two places, named new price, for the technology genre.

โœ๏ธ Exercise: A price rise

Show title, price, and price + 10% (rounded) as new_price for Technology books

Show hint

ROUND(price * 1.1, 2) AS new_price

Show solution
solution.sqlsql
SELECT title,
       price,
       ROUND(price * 1.1, 2) AS new_price
FROM books
WHERE genre = 'Technology';
Output
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚          title           โ”‚ price โ”‚ new_price โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Python for Curious Minds โ”‚ 34.99 โ”‚ 38.49     โ”‚
โ”‚ SQL in a Weekend         โ”‚ 29.99 โ”‚ 32.99     โ”‚
โ”‚ Data for Everyone        โ”‚ 31.99 โ”‚ 35.19     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Quick check

Quick check. A book costs exactly twelve dollars. Using Helen's rule, budget under twelve, standard under twenty, which label does it get? Pause and choose. The answer is B, standard. Twelve is not less than twelve, so the first test fails, and the second one passes.

Quick check
price = 12. CASE WHEN price < 12 THEN Budget WHEN price < 20 THEN Standard ELSE Premium

Summary

You can now calculate, round, rename, and label. Next, the built in functions that clean up text.

Key takeaways
  • Calculate and round
  • Name with AS
  • Label with CASE
Next up: Text Functions โ€” tidy up words