How to create LEFT JOIN with SELECT subquery using QueryBuilder in Doctrine 2?(如何在 Doctrine 2 中使用 QueryBuilder 创建带有 SELECT 子查询的 LEFT JOIN?)
问题描述
我需要限制 LEFT JOIN 结果,所以我必须使用子查询.有人可以给我建议我如何使用 Doctrine 2 做到这一点?
I need to limit LEFT JOIN results, so I must use subquery. Could somebody give me advice how can I do it with Doctrine 2?
我现在拥有的是:
$qb = $this->_em->createQueryBuilder();
return $qb->add('select', 'c,j')
->add('from', 'JobeetBundle:Category c')
->leftJoin('c.jobs', 'j', 'WITH', 'j.category = c')
->add('where', 'j.expiresAt > ?1')
->add('orderBy','j.expiresAt DESC')
->setParameter(1, new DateTime())
->getQuery()
->getResult();
但我必须更改它以将每个类别的工作结果限制为 10 个.
but I must change it to limit jobs results to 10 by every category.
推荐答案
不幸的是,这是不可能的.在这里:
Unfortunately, This is not possible. Per here:
https://groups.google.com/forum/#!topic/doctrine-user/0rNbXlD0E_8
你可以在这里使用 IN:
You can do it using IN here:
在 Doctrine 2 中执行 WHERE .. IN 子查询
这篇关于如何在 Doctrine 2 中使用 QueryBuilder 创建带有 SELECT 子查询的 LEFT JOIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Doctrine 2 中使用 QueryBuilder 创建带有 SELECT 子查询的 LEFT JOIN?


- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01