これは学生図書館のプロジェクトの一部です。
と の 2 つのテーブルがありalerts
ますborrows
。
borrows
studentID
、bookID
およびが含まれますdate of borrowing
。
alerts
は、どの生徒が何冊の本を延滞しているかを示します。
このコードは、延滞している生徒ごとに行を挿入し、延滞している本の数を数えることになっています。
Est_Return_Date = return_date + 30
insert into dbo.Alert (studentID, AlertCount)
values ((select distinct (studentID )from dbo.Borrows
where Est_Return_Date < GETDATE()
and return_date is null),
(select count( studentID) from dbo.Borrows
where Est_Return_Date < GETDATE()
and return_date is null ))