Advertisement
hexalogy

dfg

Dec 9th, 2019
1,096
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 2.38 KB | None | 0 0
  1. /* EFRAS SOPUTAN FINAL EXAM IT775 FALL 2019*/
  2.  
  3. /* a)   Insert 'Anna Kendrick' and 'Owl City' in the Artists table.  In a follow-up query, report the ArtistId assigned to each of these two new artists. */
  4.  
  5. INSERT INTO artist (Name, ArtistId)
  6. VALUES
  7. ('276','Anna Kendrick'),
  8. ('277','Owl City');
  9.  
  10. SELECT name, artistid FROM artist
  11. WHERE name = 'Anna Kendrick' OR name = 'Owl City';
  12.  
  13. /* b)   Find each artist's sales to Norwegians.  If no sales were made to Norwegians by an artist, that artist need not be reported.  (Output should have only the ArtistName and Total Sales.) */
  14.  
  15.  
  16. /* c)   Generate a report summarizing the number of tracks in each genre and provide a table with two columns--the number of tracks and genre name. */
  17.  
  18. SELECT
  19. genre.name,
  20. COUNT(*) AS '# of tracks' FROM genre
  21. INNER JOIN track ON track.genreid = genre.genreid
  22. GROUP BY genre.name;
  23.  
  24. /* d)   Which audio track has the longest length? */
  25.  
  26. SELECT name, MAX(milliseconds) FROM track;
  27.  
  28.  
  29. /* e)   What is the space, in bytes, occupied by the playlist "Classical," and how much would it cost?  (Assume that the cost of a playlist is the sum of the price of its constituent tracks.) */
  30.  
  31. SELECT
  32.     playlist.name,
  33.     SUM(track.bytes) AS 'Space',
  34.     SUM(track.unitprice) AS 'Cost' FROM playlist
  35. INNER JOIN playlisttrack ON playlisttrack.playlistid =  playlist.playlistid
  36. INNER JOIN track ON track.trackid = playlisttrack.trackid
  37. WHERE playlist.name = 'classical';
  38.  
  39.    
  40. /* f)   Find the first and last names of the employees who are older than their corresponding supervisor.  (Output should have only the FirstName and LastName in the table.) */
  41.  
  42.  
  43. /* g)   Create a table called Bonuses to store employee bonuses when tracks are sold to customers.  The table should have three columns (EmployeeId, InvoiceId, and BonusAmt).  Ensure that the table created will comply with the existing schema. */
  44.  
  45.  
  46.  
  47. /* h)   How many tracks exist where at least one of the composers has the name "John"?  (Note that "Johnson" is not a valid result--"John" must be the first, middle or last name of the composer.) */
  48.  
  49. SELECT COUNT(NAME) FROM track
  50. WHERE composer LIKE '%john %'
  51.  
  52.  
  53. /* i)   Create a view named Sales to obtain the album names along with the sales amounts.  (Output should have two columns—AlbumName and TotalSales.) */
  54.  
  55.  
  56. /* j)   Report the media type that is most favored by customers through their purchases.  (Output should be MediaType.Name.) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement