The genre that pays the rent

Boss exercise. Sales wants the single most profitable genre — the one whose sold tracks earned the most money. Each row of invoice_lines is one sale; its money is quantity * unit_price, and it points at a track, which knows its genre_id.

Build the per-genre revenue inside a subquery (join invoice_lines to tracks, group, sort, keep the top one), then match that genre id against genres.

Tables in this exercise
tracks
id title album_id genre_id duration_sec unit_price
genres
id name
invoice_lines
id invoice_id track_id quantity unit_price

Back to the chapter