You are on page 1of 2

Jonathan Herman jsh2201

Akhilesh Srivastava as5215


Coms W4111 Project 1.2

PostgreSQL Database Account Number:

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;

We sourced the BPM values for the songs from songbpm.com

Changes since part 1


o We added a zipcode field to the Users table. Collecting more
user information allows for more interesting queries.
o We added a constraint on the owns_playlist table that a
playlist can be owned by at most one user.
o We removed the number of songs (numSongs) attribute from
the Playlist table because it was redundant.

You might also like