有3张表;
表A: AID, AName;主键AID
表B: BID , BName,AID;主键BID
表C: CID,CName,BID ;主键CID
输入:AID
输出:BID,BName,NCountC。
其中NCount为BID所对应CID的个数;语句该怎么写?

解决方案 »

  1.   

    输入:AID
    输出:BID,BName,NCountC。
    实在看不懂。A,B没联系阿~
    贴出data和希望结果来看看。
      

  2.   

    select b.BID,b.BName,count(1) NCountC from B b,C c where b.AID=AID and c.BID=b.BID group by b.BID,b.BName
      

  3.   

    select b.BID,b.BName,
    (seelct count(c.*)  from c,b,where c.BID=b.BID group by b.BID,b.BName) as NCount
    from a,b
    where a.aid="输入值"
      

  4.   

    select b.BID,b.BName,
    (seelct count(c.*)  from c,b,where c.BID=b.BID group by b.BID,b.BName) as NCount
    from a,b
    where a.aid=b.aid and a.aid="要输入的AID的值"