CTGU Spring 2021-MySQL database experiment 2: basic query 5-6 levels, a total of 5 sub-questions full code + information table + clearance screenshots!

This training project is suitable for course experiments or trainings that are learning the course of "Database Principles and Applications". Content includes: single table query

Fifth level

CTGU2021 Spring-MySQL Database Experiment 2_5-Query 23-25

23. Task description

– 23. Query the ISBN, book title and inventory of each book, and sort the results in ascending order of inventory. When the inventory is the same, sort in descending order of ISBN
Insert picture description here
Insert picture description here

 use library;

######### Begin #########

##  23、查询每种图书的ISBN、书名和其库存量,并对结果按库存量升序排序,库存量相同时,按ISBN的降序排列。

select a.ISBN,b.bname,count(*)
from Books a,BookInfo b
where a.ISBN=b.ISBN
group by ISBN
order by count(*),ISBN desc;

######### End ##########


Insert picture description here

24. Task description

– 24. Query the title of each book and its inventory, and sort the results in ascending order of inventory, and sort the results in descending order of ISBN if the inventory is the same. Only return the titles and stocks of books with more than 3 books in stock.
Insert picture description here
Insert picture description here

 use library;

######### Begin #########
# 24、查询每种图书的书名和其库存量,并对结果按库存量升序排序,库存量相同则按ISBN降序排列。只返回库存量在3本以上的书名和库存量。

select a.ISBN,b.bname,count(*)
from Books a,BookInfo b
where a.ISBN=b.ISBN
group by a.ISBN
having count(*) > 3
order by count(*),a.ISBN desc; 

######### End ##########

Insert picture description here

25. Task description

25. Inquire about the amount and reason for the total amount of charges greater than 50 yuan in various circumstances in 2019.
Insert picture description here

 use library;

######### Begin #########
##   25、	查询2019年各种情况收费的总数大于50元的金额和收费原因。

select reason,sum(amount)
from Money
where year(billdate) = 2019
group by reason
having sum(amount) > 50; 

######### End ##########

Insert picture description here

Sixth pass

CTGU2021 Spring-MySQL Database Experiment 2_6-Query 26-27

26. Task description

– 26. Query the card number, name, and book number of the current borrower.
Insert picture description here
Insert picture description here

 use library;

######### Begin #########
##-- 26、	查询当前借书用户的借阅证号、姓名、书号

select a.loanNo as loanno,b.lname,a.bookNo as bookno
from Loan a,Users b
where a.loanNo = b.loanNo;

######### End ##########

Insert picture description here

27. Task description

– 27. Query the library card number, name, book title of the user who has not returned the current borrowing book after the expiration date, and sort by the library card number.
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

 use library;

######### Begin #########
# -- 27、	查询当前借书过期还没归还的用户的借阅证号、姓名、书名,并按借阅证号排序。

select Users.loanNo as loanno,Users.lname,BookInfo.bname
from Loan,Users,BookInfo,Class_User,Books
where Loan.loanNo = Users.loanNo and 
Loan.bookNo = Books.bookNo and
Books.ISBN=BookInfo.ISBN and
Users.classNo = Class_User.classNo and 
datediff(curdate(),borrowdate) > term
order by Loan.loanNo;

######### End ##########

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46478866/article/details/115258622