问题描述:

How i can set an alias for a countDistinct expr using Doctrine queryBuilder?

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

网友答案:

You can't. Here's what the countDistinct function returns:

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

You could however directly call the select function like this:

select('COUNT(DISTINCT _charges.id) AS charges')
相关阅读:
Top