select a.id,b.pid,
(select count(0) from imgType c where c.ReportToPath like '%/'+CONVERT(varchar(2),b.id)+'/%') typeCount,
(select COUNT(0) from imgInfo d where d.typeId in (select ID from imgType where c.ReportToPath like '%/'+CONVERT(varchar(2),b.id)+'/%')) imgCount,
from imgInfo a inner join imgType b on (a.typeid=b.id)