Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- What order (Invoice) was the most expensive? Which one was the cheapest?
- SELECT MAX(total)
- FROM Invoice;
- SELECT MIN(total)
- FROM Invoice;
- Which city (BillingCity) has the most orders?
- SELECT Invoice.BillingCity, SUM(Invoice.Total)
- FROM Invoice
- GROUP BY Invoice.BillingCity
- ORDER BY (Invoice.Total) DESC;
- Calculate (or count) how many tracks have this MediaType: Protected AAC audio file.
- SELECT COUNT (Track.MediaTypeId), MediaType.Name
- FROM Track
- INNER JOIN MediaType ON Track.MediaTypeId=MediaType.MediaTypeId
- WHERE MediaType.Name='Protected AAC audio file';
- Find out what Artist has the most albums? (hint: check ORDER BY)
- SELECT Artist.Name, COUNT(Artist.ArtistId)
- FROM Artist
- INNER JOIN Album ON Artist.ArtistId=Album.ArtistId
- GROUP BY Artist.ArtistId HAVING COUNT(Artist.ArtistId)
- ORDER BY COUNT(Artist.ArtistId) DESC;
- ----otra solución----
- SELECT Artist.Name, COUNT(Artist.ArtistId)
- FROM Album
- INNER JOIN Artist ON Album.ArtistId=Artist.ArtistId
- GROUP BY Album.ArtistId
- ORDER BY COUNT(Artist.ArtistId) DESC;
- What genre has the most tracks?
- SELECT Genre.Name, COUNT(Track.GenreId)
- FROM Track
- INNER JOIN Genre ON Track.GenreId=Genre.GenreId
- GROUP BY Track.GenreId HAVING COUNT(Track.GenreId)
- ORDER BY COUNT(Track.GenreId) DESC;
- ----otra solución----
- SELECT Genre.Name, COUNT(Track.GenreId)
- FROM Genre
- INNER JOIN Track ON Track.GenreId=Genre.GenreId
- GROUP BY Track.GenreId
- ORDER BY COUNT(Track.GenreId) DESC;
- Which customer spent the most money so far?
- SELECT Customer.FirstName, Customer.LastName, Customer.CustomerId, SUM(Invoice.Total)
- FROM Invoice
- INNER JOIN Customer ON Invoice.CustomerId=Customer.CustomerId
- GROUP BY Customer.CustomerId HAVING SUM(Invoice.Total)
- ORDER BY SUM(Invoice.Total)DESC;
- ----otra solución----
- SELECT Customer.FirstName, Customer.LastName, Customer.CustomerId, SUM(Invoice.Total)
- FROM Customer
- INNER JOIN Invoice ON Invoice.CustomerId=Customer.CustomerId
- GROUP BY Customer.CustomerId
- ORDER BY SUM(Invoice.Total)DESC;
- What songs were bought with each order?
- SELECT Invoice.InvoiceId, InvoiceLine.TrackId, Track.Name
- FROM Invoice
- INNER JOIN InvoiceLine ON Invoice.InvoiceId=InvoiceLine.InvoiceId
- INNER JOIN Track ON InvoiceLine.TrackId=Track.TrackId;
Add Comment
Please, Sign In to add comment