Guest User

Untitled

a guest
May 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. What order (Invoice) was the most expensive? Which one was the cheapest?
  2.  
  3. SELECT MAX(total)
  4. FROM Invoice;
  5.  
  6. SELECT MIN(total)
  7. FROM Invoice;
  8.  
  9. Which city (BillingCity) has the most orders?
  10.  
  11. SELECT Invoice.BillingCity, SUM(Invoice.Total)
  12. FROM Invoice
  13. GROUP BY Invoice.BillingCity
  14. ORDER BY (Invoice.Total) DESC;
  15.  
  16. Calculate (or count) how many tracks have this MediaType: Protected AAC audio file.
  17.  
  18. SELECT COUNT (Track.MediaTypeId), MediaType.Name
  19. FROM Track
  20. INNER JOIN MediaType ON Track.MediaTypeId=MediaType.MediaTypeId
  21. WHERE MediaType.Name='Protected AAC audio file';
  22.  
  23. Find out what Artist has the most albums? (hint: check ORDER BY)
  24.  
  25. SELECT Artist.Name, COUNT(Artist.ArtistId)
  26. FROM Artist
  27. INNER JOIN Album ON Artist.ArtistId=Album.ArtistId
  28. GROUP BY Artist.ArtistId HAVING COUNT(Artist.ArtistId)
  29. ORDER BY COUNT(Artist.ArtistId) DESC;
  30.  
  31. ----otra solución----
  32.  
  33. SELECT Artist.Name, COUNT(Artist.ArtistId)
  34. FROM Album
  35. INNER JOIN Artist ON Album.ArtistId=Artist.ArtistId
  36. GROUP BY Album.ArtistId
  37. ORDER BY COUNT(Artist.ArtistId) DESC;
  38.  
  39. What genre has the most tracks?
  40.  
  41. SELECT Genre.Name, COUNT(Track.GenreId)
  42. FROM Track
  43. INNER JOIN Genre ON Track.GenreId=Genre.GenreId
  44. GROUP BY Track.GenreId HAVING COUNT(Track.GenreId)
  45. ORDER BY COUNT(Track.GenreId) DESC;
  46.  
  47. ----otra solución----
  48. SELECT Genre.Name, COUNT(Track.GenreId)
  49. FROM Genre
  50. INNER JOIN Track ON Track.GenreId=Genre.GenreId
  51. GROUP BY Track.GenreId
  52. ORDER BY COUNT(Track.GenreId) DESC;
  53.  
  54. Which customer spent the most money so far?
  55.  
  56. SELECT Customer.FirstName, Customer.LastName, Customer.CustomerId, SUM(Invoice.Total)
  57. FROM Invoice
  58. INNER JOIN Customer ON Invoice.CustomerId=Customer.CustomerId
  59. GROUP BY Customer.CustomerId HAVING SUM(Invoice.Total)
  60. ORDER BY SUM(Invoice.Total)DESC;
  61.  
  62. ----otra solución----
  63. SELECT Customer.FirstName, Customer.LastName, Customer.CustomerId, SUM(Invoice.Total)
  64. FROM Customer
  65. INNER JOIN Invoice ON Invoice.CustomerId=Customer.CustomerId
  66. GROUP BY Customer.CustomerId
  67. ORDER BY SUM(Invoice.Total)DESC;
  68.  
  69. What songs were bought with each order?
  70.  
  71. SELECT Invoice.InvoiceId, InvoiceLine.TrackId, Track.Name
  72. FROM Invoice
  73. INNER JOIN InvoiceLine ON Invoice.InvoiceId=InvoiceLine.InvoiceId
  74. INNER JOIN Track ON InvoiceLine.TrackId=Track.TrackId;
Add Comment
Please, Sign In to add comment