看了一下,似乎没有必要,用下面这个就满足你的条件了啊
select D.DeptName as [Name],
isnull (count(s.subid),0) as JibanjianNum
from((subdepartment as sd
left outer join service    as s     on  sd.subid=s.subid)
left outer join department as d     on  sd.deid=d.deid)
where s.typeid=1 
and s.useflag='Y' 
and s.serviceid not in (select MainSerId from ServiceRelation)
group by D.DeptName
你不就是要统计条件为
s.typeid=1 
and s.useflag='Y' 
and s.serviceid not in (select MainSerId from ServiceRelation)的吗?