This project focuses on analyzing Spotify music data using SQL. It covers everything from basic data exploration to advanced SQL concepts such as CTEs, Window Functions, Aggregate Functions, Conditional Aggregation, and Subqueries.
The objective is to extract meaningful insights from Spotify datasets using SQL queries.
- π΅ Explore Spotify music dataset
- π Perform Exploratory Data Analysis (EDA)
- π Answer real-world business questions
- π Practice SQL from Beginner to Advanced
- π‘ Learn Window Functions, CTEs and Aggregate Functions
- PostgreSQL
- SQL
- Git
- GitHub
The dataset contains information about Spotify tracks including:
- π€ Artist
- π΅ Track
- πΏ Album
- π Album Type
- π Danceability
- β‘ Energy
- π Loudness
- π£ Speechiness
- πΌ Acousticness
- π» Instrumentalness
- β€οΈ Valence
- π§ Liveness
- β± Tempo
- β Duration
- π Views
- π Likes
- π¬ Comments
- π Streams
- βΆ Platform (Spotify / YouTube)
SELECT *
FROM spotify;SELECT COUNT(DISTINCT artist)
FROM spotify;SELECT DISTINCT album_type
FROM spotify;SELECT MAX(duration_min)
FROM spotify;SELECT MIN(duration_min)
FROM spotify;SELECT *
FROM spotify
WHERE duration_min = 0;DELETE FROM spotify
WHERE duration_min = 0;SELECT DISTINCT channel
FROM spotify;SELECT track
FROM spotify
WHERE stream > 1000000000;SELECT DISTINCT album, artist
FROM spotify
ORDER BY album;SELECT SUM(comments)
FROM spotify
WHERE licensed = 'true';SELECT track
FROM spotify
WHERE album_type='single';SELECT artist,
COUNT(track)
FROM spotify
GROUP BY artist;SELECT album,
AVG(danceability) AS Avg_danceability
FROM spotify
GROUP BY album;SELECT track,
energy
FROM spotify
GROUP BY track,energy
ORDER BY energy DESC
LIMIT 5;SELECT track,
SUM(views) AS total_views,
SUM(likes) AS total_likes
FROM spotify
WHERE official_video='true'
GROUP BY track
ORDER BY total_views DESC
LIMIT 5;SELECT album,
track,
SUM(views) AS total_album_views
FROM spotify
GROUP BY album,track
ORDER BY total_album_views DESC;SELECT *
FROM
(
SELECT track,
COALESCE(SUM(CASE WHEN most_played_on='Youtube' THEN stream END),0) AS streamed_on_youtube,
COALESCE(SUM(CASE WHEN most_played_on='Spotify' THEN stream END),0) AS streamed_on_spotify
FROM spotify
GROUP BY 1
) AS t1
WHERE streamed_on_spotify > streamed_on_youtube
AND streamed_on_youtube <> 0;WITH ranking_artist AS
(
SELECT artist,
track,
SUM(views) AS total_views,
DENSE_RANK() OVER
(
PARTITION BY artist
ORDER BY SUM(views) DESC
) AS rank
FROM spotify
GROUP BY artist,track
ORDER BY artist,total_views DESC
)
SELECT *
FROM ranking_artist
WHERE rank<=3;SELECT track,
artist,
liveness
FROM spotify
WHERE liveness >
(
SELECT AVG(liveness)
FROM spotify
);3οΈβ£ Calculate the difference between the highest and lowest energy values for each album using CTE.
WITH cte AS
(
SELECT album,
MAX(energy) AS highest_energy,
MIN(energy) AS lowest_energy
FROM spotify
GROUP BY album
)
SELECT album,
highest_energy-lowest_energy AS energy_diff
FROM cte
ORDER BY energy_diff DESC;- β SELECT
- β WHERE
- β ORDER BY
- β GROUP BY
- β Aggregate Functions
- β DISTINCT
- β LIMIT
- β CASE WHEN
- β COALESCE
- β Subqueries
- β Common Table Expressions (CTE)
- β Window Functions
- β DENSE_RANK()
- β DELETE
- β Data Cleaning
- β SQL Query Writing
- β Data Cleaning
- β Business Problem Solving
- β Data Aggregation
- β Window Functions
- β CTEs
- β Analytical Thinking
Please consider giving it a β on GitHub!
