Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Homework 2

Querying the Indie Game Catalog

In this assignment you will practice writing SQL queries against a database of indie video games. The database has four related tables — developers, genres, games, and reviews — and covers the real-world catalog of indie titles you may already know.

There are 30 questions worth 150 points total (5 points each). All questions use only the concepts covered in Weeks 0–2: SELECT, WHERE, ORDER BY, DISTINCT, calculated columns, aliases, NULL handling, string and date filtering, logical operators, IN, and LIKE.


The Database

The database is named indiegames and contains four tables.

developers

Studios and individuals who make games.

ColumnTypeNotes
developer_idintegerPrimary key
namevarcharDeveloper or studio name
countryvarcharCountry of origin
founded_yearintegerYear the developer was founded
websitevarcharWebsite URL — may be NULL

genres

A lookup table for game genres.

ColumnTypeNotes
genre_idintegerPrimary key
namevarcharGenre name (e.g. Roguelite, RPG)
descriptiontextDescription — may be NULL

games

The main table. Each game belongs to one developer and one genre.

ColumnTypeNotes
game_idintegerPrimary key
titlevarcharGame title
developer_idintegerReferences developers
genre_idintegerReferences genres
release_datedateRelease date
pricenumericPrice in USD (0.00 = free)
ratingnumericRating out of 10 — may be NULL (unrated games)
platformvarcharOne of: PC, Nintendo Switch, PS5, Xbox
is_early_accessbooleanTRUE if currently in Early Access
descriptiontextShort description — may be NULL

reviews

Player reviews for individual games.

ColumnTypeNotes
review_idintegerPrimary key
game_idintegerReferences games
reviewer_namevarcharReviewer’s username
scoreintegerScore from 1 to 10
review_datedateDate review was written
recommendedbooleanWhether the reviewer recommends the game
bodytextWritten review text — may be NULL (score-only reviews)

Entity-Relationship Diagram

Entity-relationship diagram for the indiegames database

The Questions

There are 30 questions, each in its own .sql file (q01.sql through q30.sql). Open each file and write your query below the comment block.

#Table(s)Question
1gamesList all columns and all rows from the games table.
2gamesList the title, price, and platform of every game.
3gamesList each game’s title, original price, and a discounted price that is 90% of the original price (column: discounted_price, rounded to 2 decimal places). Order by title.
4gamesList the title and price of all games, ordered by price from highest to lowest. Break ties alphabetically by title.
5developersList the name, country, and founding year of every developer, ordered by founding year from oldest to newest. Break ties alphabetically by name.
6gamesList each unique platform. Each platform should appear only once. Order alphabetically.
7developersList each unique country in the developers table. Each country should appear only once. Order alphabetically.
8reviewsList the reviewer name, score, and review date of all reviews where the score is 9 or higher. Order by score descending, then reviewer name.
9gamesList the title and price of all games that cost less than $15.00, ordered by price ascending. Break ties alphabetically by title.
10gamesList the title, platform, and rating of all games available on PC. Order by title alphabetically.
11gamesList the title and price of all games priced between 10.00and10.00 and 25.00 (inclusive). Order by price, then title.
12gamesList the title and platform of all games that do not yet have a rating (rating IS NULL). Order by title.
13gamesList the title and rating of all games that have a rating, ordered from highest to lowest. Break ties alphabetically.
14developersList the name and country of all developers that have no website listed. Order by name.
15gamesList the title and release date of all games released on or after January 1, 2020. Order by date, then title.
16gamesList the title and release date of all games released between January 1, 2015 and December 31, 2019 (inclusive). Order by date, then title.
17gamesList the title, platform, and early access status of all PC games that are currently in early access. Order by title.
18gamesList the title and platform of all games available on PS5 or Xbox. Order by platform, then title.
19gamesList the title and price of all games that are NOT free. Order by price ascending, then title.
20gamesList the title and platform of all games on Nintendo Switch, PS5, or Xbox. Order by platform, then title.
21developersList the name, country, and founding year of all developers based in the USA, Canada, or Australia. Order by country, then name.
22gamesList the titles of all games whose title starts with the letter H. Order alphabetically.
23gamesList the titles of all games whose title contains the word “of”. Order alphabetically.
24developersList the name and website of all developers with a website ending in .com. Order by name.
25reviewsList the reviewer name and score of all reviewers whose name starts with C (case-insensitive). Order case-insensitively by name.
26gamesList the title and platform of all Nintendo Switch games that are NOT in early access. Order by title.
27gamesList the title, genre_id, and rating of all Roguelite (genre 1) or Action (genre 7) games with a rating above 9.0. Order by rating descending, then title.
28reviewsList the reviewer name, score, and recommended status of all reviews marked recommended but with no written body (body IS NULL). Order by score descending, then reviewer name.
29gamesList the title, original price, and a sale price at 80% of the original (column: sale_price, rounded to 2 decimal places) for all games rated above 9.0. Order by sale price, then title.
30gamesList the title, platform, price, and rating of all PC games that have a rating, are NOT in early access, and cost $20.00 or less. Order by rating descending, then title.

Step 1 — Accept the Assignment

  1. Click the GitHub Classroom invitation link posted on Moodle

  2. Click Accept this assignment

  3. Wait a few seconds, then refresh the page

  4. Click the link to your personal repository


Step 2 — Clone and Open

Open a terminal in your Coder workspace (or locally) and run:

git clone https://github.com/[YOUR-REPO-URL-HERE]
cd hw02-steam-sale-[YOUR-USERNAME]
code .

Step 3 — Set Up Python

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Remember: activate the virtual environment (source venv/bin/activate) every time you open a new terminal before running grade.py.


Step 4 — Connect to the Database

Follow the same steps as hw01 to connect VSCode SQLTools to the database. Use these settings:

Connection name:  CS354
Server:           localhost
Port:             5432
Database:         indiegames
Username:         admin
Password:         admin

The database is pre-loaded with 50 games, 15 developers, 8 genres, and 77 reviews. No setup needed — start writing queries right away.

To explore the tables, run:

-- Preview a table
SELECT * FROM games LIMIT 5;
SELECT * FROM developers LIMIT 5;
SELECT * FROM reviews LIMIT 5;

Step 5 — Write Your Queries

Each question has its own .sql file. Open the file and write your query below the comment block. Example:

-- ============================================================
-- Question 1 (5 points)
-- List all columns and all rows from the games table.
-- There is no required ordering for this question.
--
-- Expected columns: all columns
-- ============================================================

-- Write your query below:
SELECT * FROM games;

Step 6 — Check Your Score Locally

Run the grader before submitting:

python3 grade.py

The first time you run it, the grader creates and loads the database automatically. Output looks like this:

✅ q01: correct    (5 pts)
✅ q02: correct    (5 pts)
❌ q03: incorrect  (0 pts)
💥 q04: error — syntax error at or near "FORM"  (0 pts)
⬜ q05: empty file  (0 pts)

Score: 10/150

Fix any issues and run grade.py again until you’re happy with your score.


Step 7 — Submit Your Work

When you’re ready to submit:

git add .
git commit -m "completed hw02"
git push

GitHub Actions will automatically run the grader on your submission. To see your results:

Go to your repo on GitHub
→ Click the Actions tab
→ Click the most recent workflow run
→ See ✅ or ❌ per question and your total score

You can push as many times as you want before the deadline — each push triggers a new grading run.


Grading

Each of the 30 questions is worth 5 points. Partial credit is not awarded — a question is either correct or not.

ComponentQuestionsPoints
Basic SELECT, ORDER BY, DISTINCTQ01–Q0735 pts
WHERE — numbers, strings, booleansQ08–Q1120 pts
NULL handling and date filteringQ12–Q1625 pts
AND, OR, NOT, IN, LIKEQ17–Q2440 pts
Combined filters and functionsQ25–Q3030 pts
Total150 pts