昨天笔试的时候碰到一个SQL的题目,没做出来,大家帮忙看下:
大概意思是:
有三张表:
表名 | 字段
Book |bno , bname , bprice
Reader |rno , rname , rage
Recorder |rno , rno ,bdate查询出借书总数大于5的读者号(rno)以及他所借数的总数该怎么写啊?想了很久没做出来
大概意思是:
有三张表:
表名 | 字段
Book |bno , bname , bprice
Reader |rno , rname , rage
Recorder |rno , rno ,bdate查询出借书总数大于5的读者号(rno)以及他所借数的总数该怎么写啊?想了很久没做出来
from Reader d
where (select count(*) from Recorder where rno=d.rno)>=5
Reader | rno , rname , rage
Recorder | rno , bno , bdate
查询出借书总数大于5的读者号(rno)以及他所借数的总数
select rno, count(distinct bno)
from Recorder
group by rno
having count(distinct bno)>5