我想将此查询更改为学说,但不能。
select * from table1
left join table2 on table2.hotel_id = table1.id
left join table3 on table2.table3_id = table3.id
left join (
select COUNT(h.hotel_id) as count, h.hotel_id as hotel from table2 h
where h.id in (1, 3) ) t1 on t1.hotel = table1.id
where table3.id in (11, 12, 13, 14, 15, 16)
and t1.count = 2
注意:t1.count是数组长度。
$qb = $this->getEntityManager()->createQueryBuilder()
->addSelect('table1')
->addSelect('table2')
->addSelect('table3')
->from(\App\Entity\...::class, 'table1')
->leftJoin('table1.table2', 'table2', 'with', 'table2.isActive = true')
->leftJoin('table2.table3', 'table3');
$qb
->andWhere(
$qb->expr()->andX(
$qb->expr()->in('table3.id', ':prop')
)
)->setParameter(':prop', $props);
这是我的选择查询,但我不使用嵌套查询。我想使用Doctrine Expr。