The document contains 8 SQL queries that analyze data from music streaming databases. The queries return album and artist sales data by joining tables, count track sales by genre and group customers by country to analyze total sales amounts.
The document contains 8 SQL queries that analyze data from music streaming databases. The queries return album and artist sales data by joining tables, count track sales by genre and group customers by country to analyze total sales amounts.
The document contains 8 SQL queries that analyze data from music streaming databases. The queries return album and artist sales data by joining tables, count track sales by genre and group customers by country to analyze total sales amounts.
SELECT * FROM albums a INNER JOIN artists ar ON a.ArtistId = ar.ArtistId ORDER BY
a.Title DESC LIMIT 3;
EJERCICIO 2
SELECT ar.Name, COUNT(ar.Name) as 'PistasVendidas'
FROM invoice_items ii INNER JOIN tracks tr ON ii.TrackId = tr.TrackId INNER JOIN albums al ON tr.AlbumId = al.AlbumId INNER JOIN artists ar ON al.ArtistId = ar.ArtistId GROUP BY ar.Name ORDER BY PistasVendidas DESC LIMIT 10;
EJERCICIO 3
SELECT al.Title, ar.Name, count(tr.Name) as NumPistas FROM invoice_items ii
INNER JOIN tracks tr ON ii.TrackId=tr.TrackId INNER JOIN albums al ON tr.AlbumId=al.AlbumId INNER JOIN artists ar ON al.ArtistId=ar.ArtistId GROUP BY al.Title ORDER BY ar.Name LIMIT 5;
EJERCICIO 4
SELECT al.Title as Álbum, COUNT(t.TrackId) as Pistas_compradas FROM tracks t
INNER JOIN albums al ON t.AlbumId = al.AlbumId GROUP BY al.Title ORDER BY Pistas_compradas DESC;
EJERCICIO 5
Select inv.CustomerId, sum(inv.Total) from customers cus
inner join invoices inv on cus.CustomerId = inv.CustomerId group by inv.CustomerId having sum(inv.Total)>=40;
Ejercicio 6 SELECT COUNT(*) as 'Total de cliente', country FROM customers GROUP BY country; EJERCICIO 7
SELECT c.Country as País, COUNT(c.Country) as Numero_de_clientes, SUM(i.Total) as
Total_de_ventas, AVG(i.Total) as Valor_promedio_de_pedido FROM customers c INNER JOIN invoices i ON c.CustomerId = i.CustomerId GROUP BY c.Country;
EJERCICIO 8
SELECT g.Name as 'Género', COUNT(t.GenreId) as 'Pistas vendidas',
ROUND(COUNT(t.GenreId) * 100.0 / (SELECT COUNT(*) FROM tracks), 3) as 'Porcentaje de pistas ' FROM tracks t INNER JOIN genres g ON t.GenreId = g.GenreId GROUP BY g.Name;