SQL>  select a.name,count(distinct b.id),count(distinct c.id) from a,b,c where a.a_id=c.a_id and a.a
_id=b.a_id group by a.name;NAME       COUNT(DISTINCTB.ID) COUNT(DISTINCTC.ID)
---------- ------------------- -------------------
li                           2                   1
zhang                        1                   2

解决方案 »

  1.   

    select 
    from 
    (select A_ID,count(id) from b group by A_ID)x,
    (select A_ID,count(id) from c group by A_ID)y,a
    where x.A_ID(+)=a.A_ID and y.A_ID(+)=a.A_ID
      

  2.   

    不好意思,写错了,
    select a.name,x.n,y.n
    from 
    (select A_ID,count(id) n from b group by A_ID)x,
    (select A_ID,count(id) n from c group by A_ID)y,a
    where x.A_ID(+)=a.A_ID and y.A_ID(+)=a.A_ID
    我没有试,你试试吧
      

  3.   

    select a.name,b.id,c.id from (select a.name as name,count(b.id) as id from a,b where a.a_id=b.a_id group by a.name) a,(select a.name as name,count(c.id) as id from a,c where a.a_id=c.a_id group by a.name) b  where a.name=b.name
      

  4.   

    我是在mysql中执行,所以不支持子查询!
      

  5.   

    感谢 jiezhi,zhaoyongzhu提供的方案,在oracle里面是可以实现的!我虽然也是一直在搞oracle的,但是这个问题是朋友问我的,他在用mysql。
      

  6.   

    已经高定 
    select a.name,count(distinct b.id),count(distinct c.id) from a,b,c where a.a_id=c.a_id and a.a_id=b.a_id  group by a.name;
    看来我只好给自己加分了!