UPDATE a
SET CountOfAA=dt.CountOf
FROM @MediaResurce a
INNER JOIN (SELECT
aa.Sku,ISNULL(COUNT(bb.sku),0) AS CountOf
FROM @MediaResurce aa
LEFT OUTER JOIN @MediaResurce_Pics bb
ON aa.sku=bb.sku
WHERE somecol = 0
GROUP BY aa.Sku
) dt ON a.sku=dt.sku
/////////////
UPDATE a
SET CountOfBB=dt.CountOf
FROM @MediaResurce a
INNER JOIN (SELECT
aa.Sku,ISNULL(COUNT(bb.sku),0) AS CountOf
FROM @MediaResurce aa
LEFT OUTER JOIN @MediaResurce_Pics bb
ON aa.sku=bb.sku
WHERE somecol = 1
GROUP BY aa.Sku
) dt ON a.sku=dt.sku