我正在使用 symfony2 和查询生成器。由于接下来的查询,我得到了混合的结果。我知道这是由于在 SELECT 中使用了聚合函数,但我没有找到任何其他方法,这正是我所需要的。任何方向将不胜感激:
public function Inventory() {
$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$qb
->add('select', 'i.id, i.name, SUM(pod.quantityorder) as quantityordered, SUM(it.quantity) as quantityreceived')
->add('from', 'AutokeenPurchasingBundle:Items i')
->leftJoin('i.purchase_order_details', 'pod')
->leftJoin('i.inventory_transactions', 'it', 'WITH', 'it.inventory_transaction_type = 1')
->add('groupBy', 'i.id')
->addGroupBy('it.item')
->addGroupBy('pod.item')
->add('orderBy', 'i.id');
$query = $qb->getQuery();
$query->useResultCache('my_cache_id');
return $result = $query->getScalarResult();
}