Welcome to 50ville, a thrilling SQL mystery!
The CS50 Duck has been stolen! The town of Fiftyville has called upon you to solve the mystery of the stolen duck. Authorities believe that the thief stole the duck and then, shortly afterwards, took a flight out of town with the help of an accomplice. Your goal is to identify:
- The Thief - Who committed the crime?
- The City - Where did the thief escape to?
- The Accomplice - Who helped the thief?
You have been provided with the fiftyville.db
SQLite database file. Using SQL queries, you will explore the database to gather clues and solve the mystery.
All you know is that the theft took place on July 28, 2023 and that it took place on Humphrey Street.
-
Download the Database:
- The database file is named
fiftyville.db
. Make sure you have this file in your working directory.
- The database file is named
-
Install SQLite3:
- If you don’t have SQLite installed, follow the instructions below for your operating system.
- Download the SQLite tools from the official SQLite website: SQLite Download Page.
- Extract the zip file and copy the
.exe
files to a folder, such asC:\sqlite
. - Add this folder to your system's PATH so you can run SQLite commands from any terminal:
- Open Control Panel > System > Advanced system settings.
- Click Environment Variables.
- Under System Variables, find the Path variable and click Edit.
- Add the path to the folder containing
sqlite3.exe
, likeC:\sqlite
.
- Open Command Prompt and type
sqlite3
to ensure it’s working.
- SQLite is pre-installed on macOS. To verify, open Terminal and type
sqlite3
. - If it’s not installed, you can use Homebrew:
brew install sqlite3
- SQLite is often pre-installed. If not, install it using your package manager:
sudo apt install sqlite3
-
Open the Database:
- Open a terminal (Command Prompt or Terminal) and navigate to the folder containing
fiftyville.db
. Run:sqlite3 fiftyville.db
- This will open the SQLite interactive shell where you can run your SQL queries.
- Open a terminal (Command Prompt or Terminal) and navigate to the folder containing
-
Load the Schema:
- To see the tables and their structure, run:
.tables
- To view the schema of a specific table, use:
Example:
PRAGMA table_info(table_name);
PRAGMA table_info(crime_scene_reports);
- To see the tables and their structure, run:
Your goal is to examine crime scene reports, interview records, bank transactions, phone calls, flight records, and more to piece together clues.
You need to determine:
- Who the thief is.
- Which city they escaped to.
- Who helped the thief (the accomplice).
Below is the structure of the tables in the database:
Column | Type | Description |
---|---|---|
id | INTEGER | Unique report ID |
year | INTEGER | Year of the crime |
month | INTEGER | Month of the crime |
day | INTEGER | Day of the crime |
street | TEXT | Street where the crime occurred |
description | TEXT | Description of the crime |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique interview ID |
name | TEXT | Name of the person interviewed |
year | INTEGER | Year of the interview |
month | INTEGER | Month of the interview |
day | INTEGER | Day of the interview |
transcript | TEXT | Transcript of the interview |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique transaction ID |
account_number | INTEGER | Bank account number |
year | INTEGER | Year of the transaction |
month | INTEGER | Month of the transaction |
day | INTEGER | Day of the transaction |
atm_location | TEXT | Location of the ATM used |
transaction_type | TEXT | Type of transaction (withdrawal/deposit) |
amount | INTEGER | Amount involved in the transaction |
Column | Type | Description |
---|---|---|
account_number | INTEGER | Unique bank account number |
person_id | INTEGER | ID of the person owning the account |
creation_year | INTEGER | Year the account was created |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique airport ID |
abbreviation | TEXT | Airport abbreviation |
full_name | TEXT | Full name of the airport |
city | TEXT | City where the airport is located |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique flight ID |
origin_airport_id | INTEGER | Origin airport ID (foreign key) |
destination_airport_id | INTEGER | Destination airport ID (foreign key) |
year | INTEGER | Year of the flight |
month | INTEGER | Month of the flight |
day | INTEGER | Day of the flight |
hour | INTEGER | Hour of the flight |
minute | INTEGER | Minute of the flight |
Column | Type | Description |
---|---|---|
flight_id | INTEGER | Flight ID (foreign key) |
passport_number | INTEGER | Passenger’s passport number |
seat | TEXT | Seat number on the flight |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique call ID |
caller | TEXT | Phone number of the caller |
receiver | TEXT | Phone number of the receiver |
year | INTEGER | Year of the call |
month | INTEGER | Month of the call |
day | INTEGER | Day of the call |
duration | INTEGER | Duration of the call (seconds) |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique person ID |
name | TEXT | Name of the person |
phone_number | TEXT | Phone number of the person |
passport_number | INTEGER | Person's passport number |
license_plate | TEXT | License plate of the person’s vehicle |
Column | Type | Description |
---|---|---|
id | INTEGER | Unique log ID |
year | INTEGER | Year of the log entry |
month | INTEGER | Month of the log entry |
day | INTEGER | Day of the log entry |
hour | INTEGER | Hour of the log entry |
minute | INTEGER | Minute of the log entry |
activity | TEXT | Recorded activity |
license_plate | TEXT | Vehicle license plate involved |
You will need to run SQL queries to extract information from the database. Below are some essential SQL commands that might be helpful for your investigation:
-
SELECT: Retrieve data from a database.
SELECT * FROM table_name;
-
WHERE: Filter records based on conditions.
SELECT * FROM table_name WHERE condition;
-
JOIN: Combine rows from two or more tables based on a related column.
SELECT * FROM table1 JOIN table2 ON table1.column = table2.column;
-
ORDER BY: Sort results by one or more columns.
SELECT * FROM table_name ORDER BY column ASC/DESC;
For a full list of SQL commands, check out the SQL reference here.
Good luck with the investigation, and may your SQL sleuthing lead you to the truth!
(inspired by CS50)