Professional Documents
Culture Documents
Interesting queries
jsh2201
1) Select s.id of most popular song and its play count. Popularity of
songs could be
used for gauging price, etc.
select * from (
select sid, count(*) as play_count
from history h group by h.sid) t2
where play_count in (
select max(play_count)
from (
select sid, count(*) as play_count
from history h
group by h.sid) t1);
2) Find the list of users whose playlists consist of only those songs
with a BPM of at most 100. This could be used for targeted
advertising.
select t.uid from owns_playlist t join (
select distinct c.pid
from contains_songs c where not exists (
(select cs.pid,ss.sid
from contains_songs cs join song ss on cs.sid = ss.sid
where cs.pid = c.pid)
except (select cs.pid,ss.sid
from contains_songs cs join song ss on cs.sid = ss.sid
where cs.pid = c.pid and ss.bpm <= 100))) s on t.pid = s.pid
3) This query produces a table of zipcode, and number of users in
the zipcode who listen to hip hop. The list is ordered from most
users in a zipcode, to least. This data could be used by bands for
scheduling tours or targeted advertising.
select zipcode, count(*) as zipCount
from interest_profile i
join users u
on i.uid = u.uid
where i.genre = 'Hip hop'
group by zipcode
order by zipCount desc;