select count(distinct c.id) from rtneo$Payment e join rtneo$Contragent c join c.realEstatesInRent r on e.inn = c.inn where not e.inn is null and not c.personalAccount is null and size(c.contracts) > 0 and size(c.realEstatesInRent)>0 and r.payOwner = true