Using the database: Write SQL queries for each of the questions below A) Modify
ID: 3872575 • Letter: U
Question
Using the database: Write SQL queries for each of the questions below
A) Modify the above query to output the number of albums that have more than 5 tracks. Number of rows returned in the result = 1
B) Find the artists that have tracks in 2 or more genres. Print the Id, and name of such artists. Number of rows returned in the result = 7
TEE Track Trackld T Album Artist Artistld Name MediaType MediaTypeld Name Tite Artistld Albumld MediaTypeld Genreld Composer Milliseconds Genre Genreld Name Playlist Playlistd Name PlaylistTrack Playlistic Trackld Bytes UnitPrice Employee Employeeld LastName FirstName InvoiceLine InvoiceLineld Invoiceld Trackld UnitPrice Quantity Customer Customerld FirstName LastName Company Address ReportsTo BirthDate HireDate Address City State Country PostalCode Phone Fax Email Invoice Invoiceld Customerld InvoiceDate illingAddress BillingCity BillingState BillingCountry State Country PostalCode Fax SupportRepld TotalExplanation / Answer
1) select Albmum.AlbumId, Albmum.Title, count(Track.AlbmumId) as track_count
from Albmum, Track
where Album.AlbumId = Track.AlbmumId
group by
Albmum.AlbumId,
Albmum.Title,
Track.AlbmumId
having track_count > 5
LIMIT 250
a)
select count(*) from (
select Albmum.AlbumId, Albmum.Title, count(Track.AlbmumId) as track_count
from Albmum, Track
where Album.AlbumId = Track.AlbmumId
group by
Albmum.AlbumId,
Albmum.Title,
Track.AlbmumId
having track_count > 5
)
b)
select a.ArtistId, a.Name
from Artist a
where (
select count(*) from Album, Track where Album.ArtistId = a.ArtistId and Album.AlbumId = Track.AlbmumId group by Track.GenreId
) > 2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.