Trying to write entity queries with group by condition using Drupal::entityQueryAggregate
. It works well for simple fields, for example:
$query = \Drupal::entityQueryAggregate('node')->condition('status', 1)->condition('type', 'node_type');
$result = $query
->groupBy('field_custom_field')
->aggregate('nid', 'COUNT')
->execute();
But now I have to select nodes aggregated by year from custom field and I can't figure out how to do it:
->groupBy('YEAR(field_custom_date)')
- doesn't work
->addExpression('YEAR(field_custom_date)', 'fcd_year')
- doesn't work
Any ideas how to implement this query?