AstraAI

Databases Β· SQL

Ask a database a question

In the curriculum:Tables (Pandas)See the map β†’

The Case. Big apps remember millions of things β€” your messages, your high scores, your friends. They keep it all in a database: a super-organised table you can ask questions to. Let's build a tiny one about pets and quiz it!

Your tools. Python's sqlite3 is a real database, running right in your browser. You ask it questions in a special language called SQL.

Investigate. Press Run. Your SQL question picks out just the pets you asked for, and the chart counts how many of each animal there are.

  • Change the WHERE line β€” ask for cats, or pets older than 3.
  • Every app you use β€” games, YouTube, even Astra β€” talks to a database like this.
your_code.py
Starting Python…
The Reveal

Starting Python… (first time only β€” a few seconds)

πŸ—’οΈ Detective's notes

Bundles your findings, chart and code into one PDF you can keep, print or hand in.

🧩 How this code works

The tools it uses

  • Matplotlib β€” your crayon box β€” it turns numbers into charts and pictures.

What this one does

  • β€’ It draws a bar chart β€” great for comparing amounts.

How to read it, top to bottom

  1. 1. Import β€” bring in the tools (listed above).
  2. 2. The data β€” the lists and numbers near the top. These are the bits you change.
  3. 3. The work β€” a little maths, or a loop that repeats a step.
  4. 4. Show it β€” print(...) writes words; plt.show() draws the picture.

Use it for your own problems

  • Change the numbers at the top and press Run β€” nothing breaks, so experiment!
  • Ask your own version of the question β€” swap in your family, your scores, your week.
  • The same tools work on any numbers β€” that's the superpower you're learning.
Need a hint?

SQL reads like English: SELECT (pick columns) FROM (which table) WHERE (a condition) ORDER BY (sort).