Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

SQL 3. Show the average length in seconds for tracks in each genre in the databa

ID: 3802454 • Letter: S

Question

SQL

3. Show the average length in seconds for tracks in each genre in the database that includes at least one title.

4. Show all genres with the number of titles in each. Include genres in which there are zero titles.

Tracks B Title ID Y Trac kNum TrackTitle Length Second MP3 RealAud Titles TitleID rtistID Title StudioID UPC Genre Genre Genre Artists Art tID Name City Region Country ebAddre Entry Date LeadSource XrefArtistsMembe 8 MemberID L B ArtistID RespParty Studios 8 StudioID StudioName Address City Region PostalCode Country WebAddress Contact EMail Phone Sales ID Members Y MemberID FirstName LastName Addre Region PostalCode Country Home Phone Work Phone EMa Gendel Birthday Sales ID Sales People salesID rst Name Last Name Initials Base Supervisor

Explanation / Answer

3. Show the average length in seconds for tracks in each genre in the database that includes at least one title.

Select avg(Tracks.LengthSeconds) as Average_Track_Length from Tracks,Titles where Tracks.TitleID = Titles.TitleID Group By Titles.Genre Having count(Titles.TitleID)>=1;


4. Show all genres with the number of titles in each. Include genres in which there are zero titles.

Select count(TitleID) as Number_Of_Title from Titles where Genre IN(Select Genre from Genre) Group By Titles.Genre
UNION
Select '0' as Number_Of_Title from Titles where Genre NOT IN(Select Genre from Genre) Group By Titles.Genre;

5. Show the number of artists which have recorded in the alternative genre.
  

Select count(ArtistID) as Alternative_Genre_Count from Titles where Genre='Alternative'