Bootstrap

数据库上机考试

自主练习

 

找出借书最多的同学

select stuname,count(*)

from borrow natural join student

group by stuid

having count(*)>=all(select count(*) from borrow group by stuid)

 

借了相同的书的同学

select b1.bookid,s1.stuname,b2.bookid,s2.stuname,bb1.bookname

from borrow b1 natural join student s1 natural join book bb1, borrow b2 natural join student s2 natural join book bb2

where b1.bookid=b2.bookid and s1.stuname>s2.stuname

 

10.13之后借书的同学的名字

select stuname,stuid

from student

where stuid in

(select stuid from borrow

where borrowdate>'2010-10-13')

 

找出只有一个学生的学院

select department

from major

where majorid in

(select majorid

from student

group by majorid

having count(*)=1)

 

找出只有一个学生的学院的那个学生

select stuname

from student s1

where not exist

;