W3cubDocs

/Drupal 8

public function QueryAggregateInterface::execute

public QueryAggregateInterface::execute()

Executes the aggregate query.

$result = $query
  ->aggregate('nid', 'count')
  ->condition('status', 1)
  ->groupby('type')
  ->executeAggregate();

Will return:

$result[0] = array('count_nid' => 3, 'type' => 'page');
$result[1] = array('count_nid' => 1, 'type' => 'poll');
$result[2] = array('count_nid' => 4, 'type' => 'story');

Return value

array A list of result row arrays. Each result row contains the aggregate results as keys and also the groupBy columns as keys:

Overrides QueryInterface::execute

File

core/lib/Drupal/Core/Entity/Query/QueryAggregateInterface.php, line 152

Class

QueryAggregateInterface
Defines a interface for aggregated entity queries.

Namespace

Drupal\Core\Entity\Query

Code

public function execute();

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!Query!QueryAggregateInterface.php/function/QueryAggregateInterface::execute/8.1.x