Gifts for Kids
Time for a small project! In this checkpoint, you'll write queries on your own, using what you've learned in the first three lessons: choosing columns, sorting, calculating, joining texts and, above all, choosing rows with WHERE.
The exercises here are a bit different from the ones so far. They say what the result should be, not how to write the query. There's often more than one correct query, so write the one that makes sense to you. If you get stuck, look back at the lesson where you learned what you need.
The project. Christmas is coming, and Pixel Shop's marketing team is preparing its Christmas campaign: a gift guide on the website, a banner with the biggest gifts, and a party for loyal customers. Over three exercises, you'll write the queries that give the team its lists. Each exercise continues where the previous one ended: the editor starts with the queries of the previous step, which may look different from yours. That's fine. Keep them, and write the new query below them, under its comment. Results then show a table for each query.
The data. The queries work with the shop's database, as always. But the team will run them again next Christmas, when the shop has other games, prices and customers, so each query has to find its rows by itself, by what's in their columns, and not by IDs or titles that you've looked up in the Tables tab. To check that, each exercise also runs your query on other data: it changes a few rows of the tables, say, gives a game another price or another release date, and the result has to be right with them too.
The task. The gift guide starts with games for kids: the games suitable for a 7-year-old (with an age rating of 7 at most) that cost $20 or less. A game that isn't out yet can't be a Christmas present, so the guide only has games that are already out. Show their title, age rating and price, the cheapest games first, and games with the same price by title:
| title | age_rating | price |
|---|---|---|
| Cube Logic | 3 | 5 |
| Word Quest | 7 | 10 |
| Bakery Story | 3 | 15 |
| Ocean Deep | 7 | 15 |
| Pixel Racer | 3 | 15 |
| Moon Farm | 3 | 20 |
Right now, all the cheap games for kids are out, so this result would be the same even if you didn't check that. With other data, it might not be.
A tip: a game that isn't out yet has no release date. Remember from the lesson on filtering how to find such rows, and why = can't find them.
Instructions
Below the comment -- 1. Gifts for kids, write the query for the games for kids, so that it shows the result above.
Start programming for free
1/3