Advertisement
AmidamaruZXC

Untitled

Oct 12th, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.10 KB | None | 0 0
  1. Exercise 1.
  2. 1select Title, PubName from Book;
  3.  
  4. 2select * from Book where PagesNum = (select max(PagesNum) from Book);
  5.  
  6.  
  7. 3select Author from Book group by Author having count(*) > 5;
  8.  
  9. 4select * from Book where PagesNum > (select avg(PagesNum) * 2 from Book);
  10.  
  11. 5select c1.CategoryName from Category c1 where exists(select * from Category c2 where c2.ParentCat = c1.CategoryName);
  12.  
  13.  
  14. 6select Author, count(*) as CountOfBooks from Book group by Author order by CountOfBooks desc limit 1;
  15.  
  16. 7-
  17.  
  18. 8select b.* from Book b inner join Copy c group by b.ISBN having count(*) > 1;
  19.  
  20. 9select b.* from Book b where (select count(*) from Book b2 where b2.PubYear <= b.PubYear) < 10 order by b.PubYear;
  21.  
  22. 10. -
  23.  
  24. Exercise 2.
  25. 1insert into Borrowing (ReaderNr, ISBN, CopyNumber, ReturnDate) select ID, 123456, 4, null from Reader where (LastName = 'Johnson' AND FirstName = 'John');
  26.  
  27. 2delete from Book where PubYear > 2000;
  28.  
  29. 3update Borrowing b, BookCat bc set ReturnDate = ReturnDate + interval 30 day where b.ReturnDate >= '20160101' and b.ISBN = bc.ISBN and bc.CategoryName = 'Databases';
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement