Brainlag
  1. Library
  2. Challenges
  3. SQL

Rank artists by listeners outside the UK

A UK label wants to know which artists travel. Count how many different listeners outside the UK each artist reaches, not how many plays.

SQLCore20 min

A label is planning a tour outside the UK and wants to know which artists already have fans there. For every artist with at least one listener outside the UK, return the artist's name and listeners: how many different listeners from outside the UK have played at least one of their songs. A listener who played the same artist ten times counts once. Listeners whose country is unknown do not count.

Most listeners first; ties in alphabetical order of name.

exercise_1.sql to run
-- artists, songs, plays and listeners are all involved

Code editor. Press Control or Command plus Enter to run the code. Tab indents; to move focus out of the editor, press Escape and then Tab.