Hi!
My Code:
WITH usa_sale AS
(
SELECT * ,
il.quantity AS purchase
FROM invoice i
LEFT JOIN invoice_line il
on il.invoice_id = i.invoice_id
WHERE i.billing_country = "USA"
ORDER BY customer_id
),
usa_sale_genre AS
(
SELECT *, g.name Genre
FROM usa_sale u
LEFT JOIN track t
ON t.track_id = u.track_id
LEFT JOIN genre g
ON g.genre_id = t.genre_id
)
SELECT Genre,
SUM(purchase) AS Purchase,
(ROUND((CAST(COUNT(quantity) AS FLOAT) / 1040) , 3) * 100) || "%" AS "%_total_p"
FROM usa_sale_genre u
WHERE Genre = "Hip Hop/Rap"
OR Genre = "Alternative & Punk"
OR Genre = "Pop"
OR Genre = "Blues"
GROUP BY genre
ORDER BY Purchase DESC
I think i got the result but i dont how to get a percentage in automatic way. I mind i want to get the percentage of total quantity using a subquery and not a mecanic way that i used above
Some one could give a hand?
Replace this line with the output/error