I am looking to show in ascending order the NameOfTrack that occur most often from the PlaylistTrack where the Playlist Genre_Name = TV Shows or 90’s music.
The three tables are setup as follows:
Track Table => TrackID, NameOfTrack
PlaylistTrack => TrackID, PlaylistID
Playlist => PlaylistID, Genre_Name
I have tried the following but it does not work:
Select track.TrackId, track.Name, playlisttrack.PlaylistId
From playlisttrack
Inner Join track on track.TrackId = playlisttrack.TrackId
Inner Join playlist on playlisttrack.playlistId = playlist.playlistId
where playlisttrack.PlaylistId = 'TV Shows' or playlisttrack.PlaylistId = '90s Music'
group by track.Name;
CodePudding user response:
Like this?
select track.Name,
count(*) track_count
from playlisttrack
inner Join track on track.TrackId = playlisttrack.TrackId
inner Join playlist on playlisttrack.playlistId = playlist.playlistId
where playlisttrack.PlaylistId = 3 or playlisttrack.PlaylistId = 5
group by track.Name
order by 2 desc;