{"id":24696769,"url":"https://github.com/ayonika2001/music_data_sql","last_synced_at":"2026-05-19T03:43:05.986Z","repository":{"id":274071806,"uuid":"921821138","full_name":"Ayonika2001/Music_data_SQL","owner":"Ayonika2001","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-24T17:34:43.000Z","size":259,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-03T02:06:45.306Z","etag":null,"topics":["csv","dbms","mysql","mysql-database","mysql-server","sql"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ayonika2001.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-24T17:19:51.000Z","updated_at":"2025-01-24T17:37:04.000Z","dependencies_parsed_at":"2025-01-24T18:35:27.215Z","dependency_job_id":null,"html_url":"https://github.com/Ayonika2001/Music_data_SQL","commit_stats":null,"previous_names":["ayonika2001/music_data_sql"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FMusic_data_SQL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FMusic_data_SQL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FMusic_data_SQL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ayonika2001%2FMusic_data_SQL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ayonika2001","download_url":"https://codeload.github.com/Ayonika2001/Music_data_SQL/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244901141,"owners_count":20528869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","dbms","mysql","mysql-database","mysql-server","sql"],"created_at":"2025-01-27T02:04:20.051Z","updated_at":"2026-05-19T03:43:05.909Z","avatar_url":"https://github.com/Ayonika2001.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# SQL Project: Music Store Data Analysis\n\nThis project involves analyzing the data of a music store using SQL. The analysis is divided into three question sets: **Easy**, **Moderate**, and **Advanced**, with each set addressing specific business questions. The dataset includes tables such as `employee`, `invoice`, `customer`, `track`, `album`, `artist`, `genre`, and `invoice_line`. The queries aim to extract actionable insights such as identifying top customers, best-performing artists, and popular genres.\n\n---\n\n## Database Setup\n\n```sql\nCREATE DATABASE music;\nUSE music;\n```\n\n---\n\n## Question Set 1 - Easy\n\n### 1. Who is the senior most employee based on job title?\n\n```sql\nSELECT first_name, last_name, title, MAX(levels) AS senior_most_employee\nFROM employee\nGROUP BY first_name, last_name, title\nORDER BY senior_most_employee DESC LIMIT 1;\n```\n\n### 2. Which countries have the most invoices?\n\n```sql\nSELECT billing_country, COUNT(invoice_id) AS most_invoice\nFROM invoice\nGROUP BY billing_country;\n```\n\n### 3. What are the top 3 values of total invoice?\n\n```sql\nSELECT total AS total_invoice\nFROM invoice\nORDER BY total_invoice DESC LIMIT 3;\n```\n\n### 4. Which city has the best customers? \n\nReturn the city with the highest sum of invoice totals.\n\n```sql\nSELECT billing_city, SUM(total) AS invoice_totals\nFROM invoice\nGROUP BY billing_city\nORDER BY invoice_totals DESC LIMIT 1;\n```\n\n### 5. Who is the best customer?\n\nThe customer who has spent the most money will be declared the best customer.\n\n```sql\nSELECT customer.customer_id, customer.first_name, customer.last_name, SUM(invoice.total) AS invoice_totals\nFROM customer\nJOIN invoice ON customer.customer_id = invoice.customer_id\nGROUP BY customer.customer_id, customer.first_name, customer.last_name\nORDER BY invoice_totals DESC LIMIT 1;\n```\n\n---\n\n## Question Set 2 - Moderate\n\n### 1. Rock Music Listeners\n\nReturn the email, first name, last name, and genre of all rock music listeners, ordered alphabetically by email.\n\n```sql\nSELECT c.first_name, c.last_name, c.email, g.name\nFROM customer AS c\nJOIN invoice AS i ON c.customer_id = i.customer_id\nJOIN invoice_line AS il ON i.invoice_id = il.invoice_id\nJOIN track AS t ON il.track_id = t.track_id\nJOIN genre AS g ON t.genre_id = g.genre_id\nWHERE g.name = \"Rock\"\nORDER BY c.email;\n```\n\n### 2. Top 10 Rock Bands\n\nReturn the artist name and total track count for the top 10 rock bands.\n\n```sql\nSELECT a.name, g.name, COUNT(t.track_id) AS total_track\nFROM artist AS a\nJOIN album AS al ON a.artist_id = al.artist_id\nJOIN track AS t ON al.album_id = t.album_id\nJOIN genre AS g ON t.genre_id = g.genre_id\nWHERE g.name = \"Rock\"\nGROUP BY a.name, g.name\nORDER BY total_track DESC LIMIT 10;\n```\n\n### 3. Tracks Longer than Average Length\n\nReturn all track names with a song length longer than the average, sorted by the longest song first.\n\n```sql\nSELECT name, milliseconds\nFROM track\nWHERE milliseconds \u003e (SELECT AVG(milliseconds) FROM track)\nORDER BY milliseconds DESC;\n```\n\n---\n\n## Question Set 3 - Advanced\n\n### 1. Amount Spent by Each Customer on Artists\n\nReturn customer name, artist name, and the total amount spent.\n\n```sql\nWITH best_selling_artist AS (\n  SELECT a.artist_id, a.name, SUM(il.unit_price * il.quantity) AS total_spent\n  FROM artist AS a\n  JOIN album AS al ON a.artist_id = al.artist_id\n  JOIN track AS t ON al.album_id = t.album_id\n  JOIN invoice_line AS il ON t.track_id = il.track_id\n  GROUP BY a.artist_id\n  ORDER BY total_spent DESC LIMIT 1\n)\nSELECT c.customer_id, c.first_name, c.last_name, bsa.name AS artist_name, SUM(il.unit_price * il.quantity) AS amount_spent\nFROM best_selling_artist AS bsa\nJOIN album AS al ON bsa.artist_id = al.artist_id\nJOIN track AS t ON al.album_id = t.album_id\nJOIN invoice_line AS il ON t.track_id = il.track_id\nJOIN invoice AS i ON il.invoice_id = i.invoice_id\nJOIN customer AS c ON i.customer_id = c.customer_id\nGROUP BY c.customer_id, c.first_name, c.last_name, artist_name\nORDER BY amount_spent DESC;\n```\n\n### 2. Most Popular Genre for Each Country\n\nDetermine the most popular genre for each country based on purchases.\n\n```sql\nWITH most_popular_genre AS (\n  SELECT g.name, i.billing_country, COUNT(il.quantity) AS purchase,\n         ROW_NUMBER() OVER(PARTITION BY i.billing_country ORDER BY COUNT(il.quantity) DESC) AS row_no\n  FROM genre AS g\n  JOIN track AS t ON g.genre_id = t.genre_id\n  JOIN invoice_line AS il ON t.track_id = il.track_id\n  JOIN invoice AS i ON il.invoice_id = i.invoice_id\n  GROUP BY g.name, i.billing_country\n)\nSELECT *\nFROM most_popular_genre\nWHERE row_no = 1;\n```\n\n### 3. Top Customer in Each Country\n\nReturn the country, top customer, and the amount spent.\n\n```sql\nWITH top_customer AS (\n  SELECT c.customer_id, c.first_name, c.last_name, i.billing_country, SUM(il.unit_price * il.quantity) AS amount_spent,\n         ROW_NUMBER() OVER(PARTITION BY i.billing_country ORDER BY SUM(il.unit_price * il.quantity) DESC) AS row_num\n  FROM customer AS c\n  JOIN invoice AS i ON c.customer_id = i.customer_id\n  JOIN invoice_line AS il ON i.invoice_id = il.invoice_id\n  GROUP BY c.customer_id, c.first_name, c.last_name, i.billing_country\n)\nSELECT *\nFROM top_customer\nWHERE row_num = 1;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayonika2001%2Fmusic_data_sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fayonika2001%2Fmusic_data_sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fayonika2001%2Fmusic_data_sql/lists"}