select d.UserID as ConsignUserID,c.UserID as DealUserID from @a c
join
( select * from @a a
join @b b on a.CompanyID=b.ConsignID
) d on c.CompanyID=d.DealID
select a1.userid,a2.userid from a a1, a a2, b where a1.companyid=b.consignid and a2.companyid=b.dealid