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

解决方案 »

  1.   

    recorder 里的字段写错了 是 rno , bno ,bdate
      

  2.   

    select count(*) as b_num,rno from recoreder group by rno having b_num>5;
      

  3.   

    select *
    from  Reader d
    where (select count(*) from  Recorder where rno=d.rno)>=5
    == 思想重于技巧 ==
      

  4.   

    Book      | bno  ,  bname  , bprice
    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