Disclaimer: These answers are only for educational purposes only. Please do not use them for cheating. Cheating doesn’t do any good for you!
In this post, I’ll present the solution to cs50 labs 7 songs problem. So, in this lab, we have to write SQL queries to answer questions about a database of songs. A database file called songs.db is provided for us. We have to write different queries to filter out specific data from the database file regarding the questions.
So let’s see the answers to all these questions,
SQL query to list the names of all songs in the database.
This query should output a table with a single column for the name of each song.
SELECT name FROM songs;
SQL query to list the songs’ names in increasing tempo order.
This query should output a table with a single column for the name of each song.
SELECT name FROM songs ORDER BY tempo;
SQL query to list the names of the top 5 longest songs, in descending order of length.
This query should output a table with a single column for the name of each song.
SELECT name FROM songs ORDER BY duration_ms DESC LIMIT 5;
SQL query that lists the names of any songs that have danceability, energy, and valence greater than 0.75.
This query should output a table with a single column for the name of each song.
SELECT name FROM songs WHERE danceability > 0.75 AND energy > 0.75 AND valence > 0.75;
SQL query that returns the average energy of all the songs.
This query should output a table with a single column and a single row containing the average energy.
SELECT avg(energy) FROM songs;
SQL query that lists the names of songs that are by Post Malone.
This query should output a table with a single column for the name of each song.
SELECT name FROM songs WHERE artist_id = (SELECT id FROM artists WHERE name == "Post Malone");
SQL query that returns the average energy of songs that are by Drake.
This query should output a table with a single column and a single row containing the average energy.
SELECT avg(energy) FROM songs WHERE artist_id = (SELECT id FROM artists WHERE name == "Drake");
SQL query that lists the names of the songs that feature other artists.
This query should output, Songs that feature other artists and will include “feat.” in the name of the song. And it should output a table with a single column for the name of each song.
SELECT name FROM songs WHERE name LIKE "%feat.%";
Hope these answers helped you. If it did, please consider sharing this post with your friends who need these answers.
