select t.name,(select count(id) from b as t1 where t1.aid=t.id) num from a as t;
这个sql还有其他什么写法吗,能做成关联查询吗?
select a.name, s.count
from a, (
select aid, count(aid) as count
from b
group by aid
) as s
where a.id = s.aid
select t.name,(select count(id) from b as t1 where t1.aid=t.id) num from a as t;
这个sql还有其他什么写法吗,能做成关联查询吗?
select a.name, s.count
from a, (
select aid, count(aid) as count
from b
group by aid
) as s
where a.id = s.aid