日期:2014-05-17 浏览次数:20386 次
select b.*,a.num from b inner join (select sid,count(1) as num from a group by sid)a on b.sid=a.sid a,b的SID上都建立索引
------解决方案--------------------
select
b.*,a.num
from
b
left join (select sid,count(1) as num from a group by sid)a
on
b.sid=a.sid
这要看你的数据分布.
两表SID有索引么?
有索引.子查询不一定慢.