Good morning, I'm taking a course and I'm stuck in an exercise.
In the exercise I have to return the maximum value of popularity of each musical genre by country, so far so good, I managed to carry out the procedure, the problem is that in the exercise country has the maximum popularity value repeats, has a country that can have two musical genres of equal popularity.
I would like to know how to display the two genres, since when I put GROUP BY it groups everything and only displays one country, and if you have another way to do it without subquery
SELECT MAX(total) total, pais, genero, id_genero
FROM(SELECT Count(*) total, BillingCountry pais, g.Name genero, g.GenreId id_genero
FROM Genre g
JOIN Track t
ON g.GenreId = t.GenreId
JOIN InvoiceLine il
ON t.TrackId = il.TrackId
JOIN Invoice i
ON il.InvoiceId = i.InvoiceId
GROUP BY 2, 3
ORDER BY 2, 1 DESC)t1
GROUP BY 2