SELECT p.* ,
CASE WHEN u.tongji IS null THEN 0 ELSE u.tongji END
FROM dbo.AS_Project AS p
LEFT JOIN ( SELECT COUNT(0) AS tongji ,
ProjectId
FROM dbo.AS_Url
WHERE ProjectId IN ( SELECT id
FROM dbo.AS_Project )
GROUP BY ProjectId
) AS u ON p.id = u.ProjectId
转载于:https://www.cnblogs.com/luckjun/archive/2011/06/21/2086022.html