NASA wants to go to Mars! Before they build their rocket, NASA needs to track information about all of the planets in the Solar System. In this lab, you'll practice querying the database with various SELECT
statements. This will include selecting different columns and implementing other SQL clauses like WHERE
to return the data desired.
You will be able to:
- Connect to a SQL database using Python
- Retrieve all information from a SQL table
- Retrieve a subset of records from a table using a
WHERE
clause - Write SQL queries to filter and order results
- Retrieve a subset of columns from a table
To get started import pandas and sqlite3. Then, connect to the database titled planets.db
.
Don't forget to instantiate a cursor so that you can later execute your queries.
# Your code here
Here's an overview of the planet's table you'll be querying.
name | color | num_of_moons | mass | rings |
---|---|---|---|---|
Mercury | gray | 0 | 0.55 | no |
Venus | yellow | 0 | 0.82 | no |
Earth | blue | 1 | 1.00 | no |
Mars | red | 2 | 0.11 | no |
Jupiter | orange | 67 | 317.90 | no |
Saturn | hazel | 62 | 95.19 | yes |
Uranus | light blue | 27 | 14.54 | yes |
Neptune | dark blue | 14 | 17.15 | yes |
Write SQL queries for each of the statements below using the same pandas wrapping syntax from the previous lesson.
# Your code here
# Your code here
# Your code here
# Your code here
# Your code here
# Your code here
Select the name, color, and number of moons for the 4 largest planets that don't have rings and order them from largest to smallest
# Your code here
Congratulations! NASA is one step closer to embarking upon its mission to Mars. In this lab, You practiced writing SELECT
statements that query a single table to get specific information. You also used other clauses and specified column names to cherry-pick the data we wanted to retrieve.