191-3 Guided Project: Answering Business Questions using SQL - FEEDBACK REQUEST

Hello there!

Doing step 3 on:

I got to the correct answer according to the solution, here´s my code and I just wanted some feedback on matters of unseen issues and things I should consider and stuff:

Write a query that returns each genre, with the number of tracks sold in the USA:


WITH qty_per_genre AS
        SELECT il.quantity, g.name      
        FROM invoice i
        INNER JOIN invoice_line il ON il.invoice_id=i.invoice_id
        INNER JOIN track t ON t.track_id=il.track_id
        INNER JOIN genre g ON g.genre_id=t.genre_id
        WHERE billing_country='USA'

SELECT name genre, SUM(quantity) as qty_sold,
       CAST(SUM(quantity) AS FLOAT)/(SELECT COUNT(*) FROM qty_per_genre) 
        AS percentage
FROM qty_per_genre 
GROUP BY genre ORDER BY qty_sold DESC


I´ve seen on many SQL topics that solutions may work but could have other issues that cannot be seen in the platforms we use and also because I´m a rookie.

Thanks in advance!

Hi Nico! You got the same answers as I did - looks good.

I’m also a student so I can’t speak to style, but it does look like you used invoice.billing_country in your WHERE statement to subset to customers in the USA, rather than customer.country as the question recommends:

" You have been given guidance to use the country value from the customers table, and ignore the country from the billing address in the invoice table."

Answers-wise doesn’t seem to have made a difference though!

1 Like

I missed that part! But I made a query to display both columns and there was no difference, so I went for the billing_country because it´s more accurate at purchase details.
Thanks for the feedback!!

Hi there. I’ve been working on this too, but have been getting different results (although the query itself ‘works’). I put my question up here: Help isolating genres in chinook.

What is wrong about what I am doing?