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)
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)
(select count(*) from B表 where aid=A表.id)
from A表
from A,B
where A.id=B.id
group by A.id
from A a,B b
where a.id=b.aid
group by a.id,a.title;
from A a inner join B b
on a.id=b.aid
group by a.id,a.title;
from a a1,b b1
where a1.id=b1.id
GROUP BY a1.id;这个才是正道。。
from a a1,b b1
where a1.id=b1.id
GROUP BY a1.id;