我正在使用symfony2和Query构建器。由于我的查询,我得到了混合的结果。我知道这是由于在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();
}