Lab: Songs

Write SQL queries to answer questions about a database of songs.

Getting Started

  1. Open your CS50 Codespace.
  2. In the terminal window, run
wget https://scienceacademy.github.io/web/songs.zip

to download a zip file of the lab code.

  1. In the terminal window, run unzip songs.zip to unzip (decompress) the file.
  2. In the terminal window, run cd songs to change directories into your songs directory.

OR

You can also use the file locally. Download the link above on your computer and then go to this link:

https://inloop.github.io/sqlite-viewer/

Drop the songs.db file you downloaded on this page to open it.

You’ve been provided with a file called songs.db, a SQLite database containing data from Spotify about songs and artists. It contains the top 100 streamed songs on Spotify in 2023.

Run sqlite3 songs.db to to open the database and run queries.

First, try typing the command .schema. This will output the CREATE TABLE statements that were used to create the tables in the database. By looking at them, you can see the columns available in each table.

Assignment

For each of the following problems, write a single SQL query that outputs the specified results. You should not assume anything about the ids of particular songs or artists (your queries should work even if the id of any song or artist were different). Finally, each query should only return the data necessary to answer the question, nothing more.

Hints

See this SQL keywords reference for some helpful hints.

Testing

check50 scienceacademy/problems/2024ap/songs

How to Submit

submit50 scienceacademy/problems/2024ap/songs