A表 文章表
id  title
1   数据1
2   数据2
3   数据3B表 回复表
id aid content
1   1  回复1
2   1  回复1
3   1  回复1
2   2  回复2用一条sql查询出A表所有数据,并统计出B表中对应回复的个数(a表中的id对应B表中的aid)

解决方案 »

  1.   

    select *,
    (select count(*)   from B表 where aid=A表.id)
    from A表
      

  2.   

    select A.id,A.title,count(*)
    from A,B
    where A.id=B.id
    group by A.id
      

  3.   

    select a.id,a.title,count(*)
    from A a,B b
    where a.id=b.aid
    group by a.id,a.title;
      

  4.   

    select a.id,a.title,count(*)as num
     from A a inner join B b
     on a.id=b.aid
     group by a.id,a.title; 
      

  5.   

    select a1.id,count(*)
    from a a1,b b1
    where a1.id=b1.id
    GROUP BY a1.id;这个才是正道。。
      

  6.   

    select a1.id,count(*)
    from a a1,b b1
    where a1.id=b1.id
    GROUP BY a1.id;