学说计数不同别名


Doctrine countDistinct alias

如何使用Doctrine queryBuilder为countDistinct expr设置别名?

$qb->addSelect($qb->expr()->countDistinct('_charges.id'));

你不能。以下是 countDistinct 函数返回的内容:

return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')';

但是,您可以像这样直接调用 select 函数:

select('COUNT(DISTINCT _charges.id) AS charges')