update Album set Num=y.Num
from Album x join
(select a.AlbumID,COUNT(*) as Num from Photo a join Album b
on a.AlbumID=b.AlbumID group by a.AlbumID) y
on x.AlbumID=y.AlbumID
from Album x join
(select a.AlbumID,COUNT(*) as Num from Photo a join Album b
on a.AlbumID=b.AlbumID group by a.AlbumID) y
on x.AlbumID=y.AlbumID