表1                       表2 
NO    BOOK              BOOK    AUTHOR
125    b12              b01       wang
125    b13              b12       li
       b13              b13       li
124    b12              b42       zhao
124    b12              b65       zhao
123    b65
122    b42
122    b01如上为图书馆例子,NO为学号 ,要找出所有读了li 写的“所有”的书的学生学号。如上即为从表1 里选出 125
怎么办啊?? 我只会建个临时的view 再从里面挑
最好解释下阿,谢谢!!

解决方案 »

  1.   

    SELECT TBL1.NO FROM TBL1 JOIN TBL2 ON TBL1.BOOK=TBL2.BOOT AND TBL.AUTHOR='li';
      

  2.   

    sorry,刚才笔误SELECT TBL1.NO FROM TBL1 JOIN TBL2 ON TBL1.BOOK=TBL2.BOOK AND TBL2.AUTHOR='li';
      

  3.   

    select no from b1 where book in(select book from b2 where hotbor=li)
      

  4.   

    select distinct(NO) from b1 where strcmp(AUTHOR,'li') = 0;
      

  5.   

    应该差不多了啊,select no from
    (
    select distinct * from b1 where book in(select book from b2 where hotbor=li)
    ) as a
    group by no
    having count(*)>1
      

  6.   

    select  no  from  table1 join table2  where   author="li" and  table1.book=table2.book;