日期:2014-05-17 浏览次数:20503 次
select a.*,isnull(b.BCount,0) as BCount
from tbMain a
left join (select ParentID,count(1) as BCount from tbDetails group by ParentID)b on a.id=b.ParentID
--假设A,B 以ID为关联
SELECT A.*, BCount=ISNULL(( SELECT COUNT(*) FROM B where ID=A.ID ),0) FROM A