Возможно, это может помочь вам в дальнейшем.
Объявление таблиц
DECLARE @tCustomers TABLE (ID INT, MAINID INT) INSERT INTO @tCustomers VALUES
(1, 1), --Company A
(2, 1), --Employee A of Company A
(3, 1), --Employee B of Company A
(4, 4), --Company B
(5, 4) --Employee A of Company B
DECLARE @tCommunication TABLE (ID INT, SuperId INT, DateCreated DATE, Communication VARCHAR(500))
INSERT INTO @tCommunication VALUES
(1, 2, '20180101','abcdefghijkl'), --Comm of Employee A of Company A
(2, 2, '20171001','abcdefghijkl'), --Comm of Employee A of Company A
(3, 3, '20191002','abcdefghijkl'), --Comm of Employee B of Company A
(4, 5, '20171003','mnopqrstuvwxyz') --Comm of Employee A of Company B
Запрос
SELECT DISTINCT c.ID, c.MAINID AS CompanyID, e.ID AS EmployeeId
FROM @tCustomers e
INNER JOIN ( SELECT SuperId --Comm of an Employee older than 365 days
FROM @tCommunication
WHERE DATEDIFF(DAY, DateCreated, GETDATE()) > 365
) a
ON a.SuperId = e.ID
INNER JOIN @tCustomers c
ON c.ID = e.MAINID
Результат
ID | CompanyID | EmployeeId
===========================
1 | 1 | 2
4 | 4 | 5