我正在嘗試計算使用HIS: 為查詢返回的不同ID數(shù) $query = $repo->createQueryBuilder('prov')
->select('c.id')
->innerJoin('prov.products', 'prod')
->innerJoin('prod.customerItems', 'ci')
->innerJoin('ci.customer', 'c')
->where('prov.id = :brand')
->setParameter('brand', $brand)
->countDistinct('c.id')
->getQuery();我收到此錯誤: Attempted to call method "countDistinct" on class "DoctrineORMQueryBuilder" [...] 我也試過 $query = $repo->createQueryBuilder('prov')
->select('c.id')
->innerJoin('prov.products', 'prod')
->innerJoin('prod.customerItems', 'ci')
->innerJoin('ci.customer', 'c')
->where('prov.id = :brand')
->setParameter('brand', $brand)
->expr()->countDistinct('c.id')
->getQuery();導(dǎo)致此錯誤的原因: Error: Call to a member function getQuery() on a non-object in 我找不到任何其他指示,說明如何與documentation 不同地執(zhí)行此操作 countDistinct是Expr類的方法,COUNT DISTINCT需要在SELECT語句中: $qb = $repo->createQueryBuilder('prov');
$query = $qb
->select($qb->expr()->countDistinct('c.id'))
->innerJoin('prov.products', 'prod')
->innerJoin('prod.customerItems', 'ci')
->innerJoin('ci.customer', 'c')
->where('prov.id = :brand')
->setParameter('brand', $brand)
->getQuery();應(yīng)該行得通。 或者干脆: $query = $repo->createQueryBuilder('prov')
->select('COUNT(DISTINCT c.id)')
->innerJoin('prov.products', 'prod')
->innerJoin('prod.customerItems', 'ci')
->innerJoin('ci.customer', 'c')
->where('prov.id = :brand')
->setParameter('brand', $brand)
->getQuery(); |
免責聲明:本站部分文章和圖片均來自用戶投稿和網(wǎng)絡(luò)收集,旨在傳播知識,文章和圖片版權(quán)歸原作者及原出處所有,僅供學習與參考,請勿用于商業(yè)用途,如果損害了您的權(quán)利,請聯(lián)系我們及時修正或刪除。謝謝!

始終以前瞻性的眼光聚焦站長、創(chuàng)業(yè)、互聯(lián)網(wǎng)等領(lǐng)域,為您提供最新最全的互聯(lián)網(wǎng)資訊,幫助站長轉(zhuǎn)型升級,為互聯(lián)網(wǎng)創(chuàng)業(yè)者提供更加優(yōu)質(zhì)的創(chuàng)業(yè)信息和品牌營銷服務(wù),與站長一起進步!讓互聯(lián)網(wǎng)創(chuàng)業(yè)者不再孤獨!
掃一掃,關(guān)注站長網(wǎng)微信
大家都在看