简单查询,送分的,来人指教小弟
CARD借书卡:(CNO 卡号、NAME 姓名、CLASS 班级)
BOOKS图书:(BNO 书号、BNAME 书名、AUTHOR 作者、PRICE 单价、QUANTITY 库存册数)
BORROW借书记录:(CNO 借书卡号、BNO 书号、RDATE 还书日期)
查询借书最多同学班上所有同学的借书总量
[解决办法]
select sum(bno)
from (
select top 1 count(bno)bno
from BORROW a left join card b on a.cno=b.cno
group by class
order by bno desc
)a
[解决办法]
select top 1 class,
class_borrow_num
from
(
select c.class,
c.cno,
b.bno,
sum(bno) over(partition by class) as class_borrow_num,
count(bno) over(partition by cno) as borrow_num
from borrow b
inner join card c
on t.cno = c.cno
)t
order by borrow_num desc
select sum(bno)
from (
select top 1 count(bno)bno
from BORROW a left join card b on a.cno=b.cno
group by class
order by bno desc
)a
select count(*)
from card a inner join borrow b on a.cno = b.cno
where a.class = (select top 1 c.class
from card c inner join borrow d on c.cno = d.cno
group by c.class
order by count(*) desc)