Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. /* a. Find distinct track names that start with “Z”.Sort the output alphabetically.*/
  2.  
  3. /*select distinct track.Name
  4. from Track where Name like 'Z%' order by Name;*/
  5.  
  6.  
  7. /* b. Find the first names of the employees who are older than their supervisor.
  8. Hint: ReportsTo attribute in Employee table stores the EmployeeId of the supervisor. Sort the output alphabetically*/
  9.  
  10. /*select FirstName from Employee as E1
  11. where BirthDate >
  12. (select BirthDate from Employee where EmployeeId = E1.ReportsTo)
  13. order by FirstName;*/
  14.  
  15.  
  16. /* c. Find the name of the highest priced track. If more than one track has the highest
  17. price, return the names of all such tracks. Sort the output alphabetically based on the track name*/
  18.  
  19. /*select Track.name from Track
  20. where UnitPrice >=
  21. (select max(e.UnitPrice) from Track as e)
  22. order by Name;*/
  23.  
  24.  
  25. /* d. Find a list containing the total amount spend by a customer. Include the customer’s id and
  26. the last names along with the total amount. For customers who did not make any purchase, make sure to include
  27. them as well (the total should be 0.00 for those customers).BUG HERE DOESNT WORK HOW SUPPOSED TO PROBS*/
  28.  
  29. /*select CustomerId, LastName, Total as Total_Spent
  30. from Customer Natural right outer join Invoice;*/
  31.  
  32.  
  33. /* e. Find the title of the highest priced album CHECK IF WORKS*/
  34.  
  35. /*select Title from Album natural join Track
  36. group by AlbumId having sum(UnitPrice) >= all
  37. (select sum(UnitPrice) from Track group by AlbumId);*/
  38.  
  39.  
  40. /* f. Finda distinct list containing the titles of albums that are never sold. Consider
  41. an album never sold if none of its tracks are sold. Sort the output alphabetically.*/
  42.  
  43. /*select distinct Title
  44. from Album natural join Track natural join invoiceline
  45. group by AlbumId
  46. having sum(Quantity) = 0
  47. order by Title;*/
  48.  
  49.  
  50. /* g. Create a view that returns customers’ first and last names along with
  51. corresponding sums of all their invoice totals. Name the view as “CustomerInvoices.” */
  52.  
  53. /*create view CustomerInvoices as
  54. select FirstName, LastName, sum(Total) as InvoiceTotal
  55. from Customer natural join invoice
  56. group by CustomerId;
  57.  
  58. select* from CustomerInvoices;*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement