select A.aId, (select count(1) from B where B.aId = a.aId) c from A
order by c
表A有30W+数据
表B有18W+数据
用上面sql查要10分钟,如果去掉order by则在2秒内,求高手指导怎么优化
select A.aId, (select count(1) from B where B.aId = a.aId) c from A
order by c
表A有30W+数据
表B有18W+数据
用上面sql查要10分钟,如果去掉order by则在2秒内,求高手指导怎么优化
有高人指点,这样写能控制在10秒左右,但不是理解
select A.aId, NVL(B.c,0) from A LEFT JOIN (select aId,count(1) c from B group by aId) B ON A.AID=B.AID
order by B.c