I am not very good at SQL and i dont know if I am writing these queries correctly. My answer for each question is provided below each question. Any tips/corrections greatly appreciated.
For both question, i dont know if i wrote my WHERE clause correctly with the nested SELECT.
- Find all tracks of type audio (MediaType.name equal to "audio") which have length longer than the average length of all other tracks with the same type
my answer:
SELECT *
FROM Track INNER JOIN MediaType
ON Track.MediaTypeId = MediaType.MediaTypeId
WHERE Track.Milliseconds > (SELECT AVG(Milliseconds) FROM Track)
AND MediaType.name = 'audio'
- Find name(s) of the customer(s) from US that do not belong to a company and who have overall paid the most of any US customers
my answer:
SELECT FirstName, LastName
FROM Customer INNER JOIN Invoice
ON Customer.CustomerId = Invoice.CustomerId
WHERE Customer.Country = 'US' AND Customer.Company = null AND Invoice.Total = (SELECT MAX(total) FROM Invoice)