The Tables of Pixel Shop
Pixel Shop's database has five tables. You know two of them already:
games– the games the shop sells.customers– the shop's customers: their name, email and city, the day they joined (joined), andreferred_by, the ID of the customer who recommended the shop to them.orders– one row for each order: who placed it (customer_id), when (ordered_at), and itsstatus:paid, orrefundedwhen the customer got their money back.order_items– what each order had in it: the order (order_id), the game (game_id), how many copies (quantity) and thepricethe customer paid for one copy. In a sale, that's less than the game's price.reviews– the reviews of games: the game, the customer, thestarsfrom 1 to 5, and acomment.
The tables games, customers and orders have a column id with a number that identifies each row: no two rows of a table have the same one. Such a column is the table's primary key. Other tables use it to point at a row. Here's the first order:
| id | customer_id | ordered_at | status |
|---|---|---|---|
| 1 | 1 | 2024-01-20 | paid |
Its customer_id is 1, so it was placed by the customer whose id is 1: Emma Clark. And the rows of order_items whose order_id is 1 say what she bought:
| order_id | game_id | quantity | price |
|---|---|---|---|
| 1 | 3 | 1 | 20 |
| 1 | 6 | 1 | 5 |
The games 3 and 6, Moon Farm and Cube Logic. A column that points at the rows of another table, such as customer_id or game_id, is a foreign key. Thanks to them, the shop keeps each customer and each game just once, however many orders there are. For now, you can follow them by hand in the Tables tab; later, you'll learn to combine tables in one query.
Some cells say NULL. That's not a text, it means that there's no value: the shop doesn't know Ava Green's city, Robot Rebellion and Mystery Manor haven't come out yet, and nobody recommended the shop to Emma Clark. NULL isn't zero or empty text, and it has rules of its own, which you'll learn soon.
Instructions
Show the whole table order_items.
| order_id | game_id | quantity | price |
|---|---|---|---|
| 1 | 3 | 1 | 20 |
| 1 | 6 | 1 | 5 |
| … | … | … | … |
Below it, show the stars and the comment of every review. Some reviews have no comment:
| stars | comment |
|---|---|
| 5 | Best RPG I have played in years! |
| 4 | Great story, a bit long. |
| 5 | NULL |
| … | … |
Start programming for free
7/8