============================================
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.
============================================
5A (3p)
(i) (1p)
What does the following relational algebra expression compute (answer in plain text):
tau[x](pi[playlistName,COUNT( *) -> x](sigma[playlistName=playlist](Playlists × InList)))
(ii) (2p)
Translate the following relational algebra expression(s) to corresponding SQL:
let R1 = gamma[user,track,COUNT( *) -> nrTimes](PlayLog)
sigma[ avgNrTimes>=10](gamma[track,AVG(nrTimes) -> avgNrTimes](R1))
(Check original exam on the course webpage for properly formatted versions.)
============================================
5B (4p)
Translate the following SQL query to relational algebra:
SELECT album, MAX(trackNr) AS nrOfTracks, SUM(length) AS totalLength
FROM Albums, TracksOnAlbum, Tracks
WHERE albumId = album AND trackId = track
GROUP BY albumId
ORDER BY totalLength DESC;
============================================
5C (6p)
Write a relational algebra expression that lists the artist(s) appearing in the highest number
of distinct playlists. In case of a tie for highest number of different playlists, list all such
artists.