CTGU実験2:基本的なクエリ5〜6レベル
このトレーニングプロジェクトは、「データベースの原則とアプリケーション」のコースを学習しているコース実験またはトレーニングに適しています。コンテンツに含まれるもの:単一テーブルクエリ
第5レベル
CTGU2021Spring-MySQLデータベース実験2_5-クエリ23-25
23.タスクの説明
– 23. ISBN、書籍のタイトル、各書籍の在庫を照会し、結果を在庫の昇順で並べ替えます。在庫が同じ場合は、ISBNの降順で並べ替えます。
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 ##########
24.タスクの説明
– 24.各書籍のタイトルとその在庫を照会し、結果を在庫の昇順で並べ替え、在庫が同じ場合はISBNの降順で結果を並べ替えます。在庫が3冊を超える本のタイトルと在庫のみを返却してください。
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 ##########
25.タスクの説明
25。2019年のさまざまな状況で50元を超える料金の合計額と理由についてお問い合わせください。
use library;
######### Begin #########
## 25、 查询2019年各种情况收费的总数大于50元的金额和收费原因。
select reason,sum(amount)
from Money
where year(billdate) = 2019
group by reason
having sum(amount) > 50;
######### End ##########
6回目のパス
CTGU2021Spring-MySQLデータベース実験2_6-クエリ26-27
26.タスクの説明
– 26.現在の借り手のカード番号、名前、および本番号を照会します。
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 ##########
27.タスクの説明
– 27.有効期限が切れた後、現在の借書を返却していないユーザーの番号、名前、本のタイトルを照会し、借用カードの番号で並べ替えます。
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 ##########