Advertisement
Aodai

Untitled

Dec 18th, 2020
2,567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 2.37 KB | None | 0 0
  1. USE dbBookStore
  2.  
  3. --16.List the book code and the book title of each book that has the type of TRA, PSY or CMP.
  4. SELECT BookCode, Title FROM tblBOOK WHERE Category IN('TRA', 'PSY', 'CMP')
  5.  
  6. --17.How many employees does the books store have?
  7. SELECT SUM(NumberEmployees) AS [Total NUMBER OF employees IN books store] FROM tblBRANCH
  8.  
  9. --18.For each book published by Tor Books, list the book code, book title, and price.
  10. SELECT BookCode, Title, Price FROM tblBOOK AS tbl1, tblPUBLISHER AS tbl2 WHERE (tbl2.PublisherName='Tor Books' AND tbl1.PublisherCode = tbl2.Code)
  11.  
  12. --19.List the book code, book title, and price of each book published by Tor Books that has a book price of less than $15
  13. SELECT BookCode, Title, Price FROM tblBOOK AS tbl1, tblPUBLISHER AS tbl2 WHERE (tbl1.Price < 15 AND tbl2.PublisherName='Tor Books' AND tbl1.PublisherCode = tbl2.Code)
  14.  
  15. --20.List the number of books published every year at the existing publishers.
  16. SELECT PublisherName, PublicationYear, COUNT(*) AS [NUMBER OF books published every YEAR BY a certain publisher] FROM tblBOOK AS tbl1, tblPUBLISHER AS tbl2 WHERE tbl1.PublisherCode=tbl2.Code
  17. GROUP BY PublisherName,PublicationYear
  18. ORDER BY PublicationYear,PublisherName
  19.  
  20. --21.List the book code, book title, author's name for a certain branch (name of the branch is passed as parameter)
  21. GO
  22. CREATE PROCEDURE GetBranchInformation @BranchName nvarchar(20)
  23. AS
  24. SELECT tbl1.BookCode, Title, LastNameAuthor + ' '+ FirstNameAuthor AS [Author's name] FROM tblBOOK AS tbl1, tblAUTHOR AS tbl2, tblINVENTORY AS tbl3, tblBRANCH AS tbl4  , tblWROTE AS tbl5
  25. WHERE (tbl4.BranchID=tbl3.BranchID AND tbl3.BookCode=tbl1.BookCode AND tbl5.BookCode=tbl3.BookCode AND tbl2.AuthorID=tbl5.AuthorID AND tbl4.BranchName=@BranchName)
  26.  
  27. EXEC GetBranchInformation @BranchName='Abbey';
  28.  
  29. --22.List the number of books written by a certain author (name of the author is passed as parameter)
  30. GO
  31. CREATE PROCEDURE GetNumberOfBooks @Author nvarchar(30)
  32. AS
  33. SELECT LastNameAuthor + ' '+ FirstNameAuthor AS [Author's name],COUNT(*) AS [Books written BY a certain author] FROM tblBOOK AS tbl1, tblAUTHOR AS tbl2, tblINVENTORY AS tbl3, tblWROTE AS tbl4
  34. WHERE(tbl3.BookCode=tbl1.BookCode AND tbl4.BookCode=tbl3.BookCode AND tbl2.AuthorID=tbl4.AuthorID AND (tbl2.LastNameAuthor + ' ' + tbl2.FirstNameAuthor = @Author))
  35. GROUP BY LastNameAuthor,FirstNameAuthor
  36.  
  37. EXEC GetNumberOfBooks @Author='Jones Max';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement