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;SELECTCOUNT(DISTINCT artist)
FROM spotify;SELECT DISTINCT album_type
FROM spotify;SELECTMAX(duration_min)
FROM spotify;SELECTMIN(duration_min)
FROM spotify;SELECT*FROM spotify
WHERE duration_min =0;DELETEFROM 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;SELECTSUM(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 DESCLIMIT5;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 DESCLIMIT5;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 BY1
) 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 BYSUM(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 >
(
SELECTAVG(liveness)
FROM spotify
);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!
