$qb = $this->o->createQueryBuilder('o');
$sub = $this->em->createQueryBuilder();
$sub->select("o.id"); //notice this : cause e.offer is foreign key of o.id
$sub->from(ExcludedByOffer::class, "e");
$sub->andWhere('e.offer = o.id')
->andWhere('e.aff = :aff');
$qb->select('count(o.id)')
->where('o.adv=:adv')
->andWhere($qb->expr()->not($qb->expr()->exists($sub->getDQL())))
->setParameters(['adv' => $adv,
'aff' => $aff
]);
return $qb->getQuery()->getSingleScalarResult();
参考
https://stackoverflow.com/questions/31536137/doctrine-not-exists-subquery/31536545
https://stackoverflow.com/questions/9214471/count-rows-in-doctrine-querybuilder