------解决方案-------------------- 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 books b,borrow c,card d,
(select top 1 class,count(distinct name) as num from card a,borrow b where a.cno=b.cno group by class order by num desc ) a
where a.class=d.class and d.cno=c.cno and c.bno=b.bno ------解决方案-------------------- 借书最多的同学,所在班级的总的借书量:
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
&n