5.Consider以下庫架構數據庫關係代數,SQL查詢
Books (book_no,title,authors,publisher)
Borrower(borrower_id, name, DOB, job)
Borrowed(borrower_id,book_no,date)
寫關係代數
- 一個下列查詢。查找借用「Wiley」發佈的3本以上書籍的借款人的姓名和借閱人ID
- b。查找借用「wiley」
- 發佈的任何書的借用人的姓名c。找到每個借款人借入的書籍的平均數量。
5.Consider以下庫架構數據庫關係代數,SQL查詢
Books (book_no,title,authors,publisher)
Borrower(borrower_id, name, DOB, job)
Borrowed(borrower_id,book_no,date)
寫關係代數
按你的問題,SQL查詢是這樣
問題1
select B.borrower_id, B.name
from Borrower as B, Borrowed as Bw, Books as Bk
where B.borrower_id = Bw.borrower_id
and Bw.book_no = Bk.book_no
and Bk.publisher = 'Wiley'
group by B.borrower_id, B.name
having count(Bw.borrower_id) > 3
問題2
select B.name
from Borrower as B, Borrowed as Bw, Books as Bk
where B.borrower_id = Bw.borrower_id
and Bw.book_no = Bk.book_no
and Bk.publisher = 'Wiley'
group by B.name
問題3
select B.borrower_id, B.name, count(Bw.borrower_id) as cnt
from Borrower as B, Borrowed as Bw, Books as Bk
where B.borrower_id = Bw.borrower_id
and Bw.book_no = Bk.book_no
group by B.borrower_id, B.name
你到目前爲止嘗試過什麼? – Rams
你有什麼問題?你到目前爲止嘗試了什麼? –
a。你需要加入表格並按照操作進行分組,並給出條件Wiley,b。通過加入所需的表格簡單地給出條件,c。與'a'相同,但不需要條件,只需要計數 – Rams