I should learn to write like opengeek does on this section of forums. A recommendation for this kind of queries is to use next kind of approach for select() and groub by methods if planning to port the possible extra to multiple database platforms and to keep the code database agnostic.
$agency_query ->select(array(
$modx->getSelectColumns('Agencies', 'Agencies'),
$modx->getSelectColumns('Reviews', 'Reviews'),
/* If reviews and agencies share same column names, add third option "re_" for example
to distinct the columns with prefix re_ when used in the loop for getCollection */
'total_score' => "count({$modx->escape('Reviews')}.{$modx->escape('score')}"
/* This will alias the count() function to total_score to be use in the output of the query
Eg. the array associative key is turned to alias, same goes for subqueries etc..
which you might have notice be used in the article
*/
));
Same goes for the groupby() where MySQL can have one column only by SQL standard you have to list all columns of the query that are not aggregate grouping functions (correct me if wrong). A quick and dirty solution I've used is to use the same getSelectColumns function in this manner
$agency_query ->groupby($modx->getSelectColumns('Agencies', 'Agencies') .",".$modx->getSelectColumns('Reviews', 'Reviews'));
This way the columns are always escaped. Could select certain columns if there would be need for it, they just need to match the cols in the select clause.
Hopefully did not shoot badly off, few months away from xPDO world and I have forgot most of it