CREATE VIEW AccountUserTerritory2View (id, accountId, territory2Id, userid, roleInTerritory2, lastModifiedDate ) 
AS
SELECT UU.id, AA.ObjectId AccountId, UU.territory2Id, UU.userId, UU.RoleInTerritory2, UU.LastModifiedDate
FROM (UserTerritory2Association UU JOIN ObjectTerritory2Association AA ON UU.territory2Id=AA.territory2Id)
	JOIN AccountTeamMember TT ON TT.accountId=AA.ObjectId AND TT.userId=UU.userId
WHERE AA.SobjectType='Account'
;

