这个嵌套查询,还有其他什么方式吗

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

阅读 2.7k
1 个回答
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
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题