============================================
Schema reposted from previous block for convenience:
Tracks(trackId, title, length)
length > 0
Artists(artistId, name)
Albums(albumId, title, yearReleased)
TracksOnAlbum(album, trackNr, track)
album -> Albums.albumId
track -> Tracks.trackId
(album, track) unique
trackNr > 0
Participates(track, artist)
track -> Tracks.trackId
artist -> Artists.artistId
Users(username, email, name)
email unique
Playlists(user, playlistName)
user -> Users.username
InList(user, playlist, number, track)
(user, playlist) -> Playlists.(user, playlistName)
track -> Tracks.trackId
PlayLog(user, time, track)
user -> Users.username
track -> Tracks.trackId
(user, time) unique
Use the relations for the music site from [above] when answering the following problems. When you are asked to list all X, you need only return the key attributes of X.
============================================
4A (4p)
(i) (2p)
Write an SQL query that lists all artists appearing on any album released this year (2013).
(ii) (2p)
Write an SQL query that lists, for each user, how many playlists that user has.
============================================
4B (6p)
Write an SQL query that lists, for each track, its trackId and title, together with the number of times that track has been played, and the number of distinct users that have played it.
============================================
4C (8p)
Write an SQL query that finds the title, length and album title of the longest track in the database. If the track appears on more than one album, list the album where it appeared first. If more than one track of the same length qualifies, list the one that was released first, as given by the album it appears on. If there is still a tie, list all such tracks.
============================================