数据库!sql再次请教!

来源:百度知道 编辑:UC知道 时间:2024/07/07 12:15:03
(1)平均每本借书证的借书册数。(2)哪个系的同学平均借书最多(3)最近两年都未被借过的书(4) 今年那种书出借最多?
1.假定使用的“book”、“card”、“borrow”三个表
book(书号bno,书名title,出版社press,年份year,作者author,价格price,总藏书量total,现有库存remains)
card(卡号cno,姓名cname)
borrow(卡号,借书证号,借期borrow_date,还期return_date)
多谢啦,虽然多了点,另有分送哈

select avg(借书册书)
from borrow

select top 1 avg(借书)
order by 借书 desc
group by 同学名

book(bno,title,press,year,author,price,total,remains)
card(cno,cname)
borrow(cno,bno,borrow_date,return_date)

(1)平均每本借书证的借书册数。
select count(*)/(select count(distinct cno) from borrow )
from borrow

(2)哪个系的同学平均借书最多
缺少表,学生表,借书号---学号---哪个系

(3)最近两年都未被借过的书
select title 
from book
where bno not in(select bno 
                 from borrow 
                 where borrow_date between (select dateadd(yyyy,-2,getDate()))