update c
set
   AttachmentCount = a.AttachmentCount
   ,AttachmentPrivateCount = a.AttachmentPrivateCount
from
    (select
        a.ConnectionID, COUNT(*) - SUM(cast(a.IsPrivate as int)) AttachmentCount, SUM(cast(a.IsPrivate as int)) as AttachmentPrivateCount
    from dbo.Attachment a
    group by a.ConnectionID) a
    inner join dbo.Connections c on a.ConnectionID = c.ID